Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A Show And Tell implementation for iOS 11.0 based on CoreML

NotificationsYou must be signed in to change notification settings

jcao-ai/ShowAndTell

Repository files navigation

ShowAndTell

Show and Tell: A Neural Image Caption Generator

🎉🎉🎉 Keras part is public now

Brief

Pull requests and issues:@litleCarl

A CoreML implementation of the image-to-text model described in the paper:

"Show and Tell: Lessons learned from the 2015 MSCOCO Image CaptioningChallenge."

Oriol Vinyals, Alexander Toshev, Samy Bengio, Dumitru Erhan.

IEEE transactions on pattern analysis and machine intelligence (2016).

Full text available at:http://arxiv.org/abs/1609.06647

Demo

Usage

Simple use

letshowAndTell=ShowAndTell()letresults= showAndTell.predict(image: uiimage2predict, beamSize:3, maxWordNumber:30)
// Parameter explaination//    image:         The image to be used to generate the caption.//    beamSize:      Max caption count in result to be reserved in beam search.(Affect the performance greatly)//    maxWordNumber: Max number of words in a sentence to be predicted.classShowAndTell{...func predict(image:UIImage, beamSize:Int=3, maxWordNumber:Int=20)->PriorityQueue<Caption>...}

Benchmark (Tested on iPhone 7+, welcome PR for more devices)

maxWordNumber = 20maxWordNumber = 30
beamSizeTime (ms)
1480.12
2845.78
31443.82
42001.30
52648.48
63158.53
74179.14
84861.66
96003.65
107087.97
118134.95
129627.79
beamSizeTime (ms)
1451.12
21194.65
31965.27
42971.92
53798.28
64391.35
75714.87
86937.60
98482.03
1010421.52
1112460.80
1213777.67

Line chart for Time vs Beam Size (WhenmaxWordNumber = 30)

So it is recommeneded to setbeamSize=1 on mobile devices due to less gpu/cpu time usage for saving battery life.

Requirements

  • iOS 11.0+
  • Xcode 9.0+ (Swift 4.x)

Original Model

This coreml model is exported from keras which is trained with MSCOCO dataset for about 40k steps. And presently it is not in the state of art yet. You may not use this in production.I trained the dataset with only one GTX Force 1080Ti for about 48 hours and currently don't have more time to train on it.Hope for community to keep on it.

Keras part

  • Train
        python ./train.py --weight_path WEIGHT_FILE_PATH_TO_CONTINUE_TRAINING  --TFRecord_pattern TFRECORD_FILE_PATTERN
    For example:
        python ./train.py --weight_path ./keras_weight/weights_full.h5  --TFRecord_pattern ./tfrecords/train-?????-of-00256
  • Test
        python ./inference.py --weight_path WEIGHT_FILE_PATH  --image_path TEST_IMAGE_PATH --max_sentence_length 20
    For example:
        python ./inference.py --weight_path ./keras_weight/weights_full.h5  --image_path ./test.jpg --max_sentence_length 20
  • Convert to CoreML Model
        python ./convert_coreml.py --export_lstm False
    export_lstm determine whether to export the inception part or lstm part model.(The whole model is split into 2 parts. One for image encoding, one for decoding words)

Pretained Weight

Pretained Keras weight file will be uploaded to google driver in short time.

Training dataset

We use MS-COCO dataset, you can fetch raw data and build them into tfrecords according to the origin tensorflowim2txt

TODO

  • Train on the dataset to 100k steps. (currently 40k)
  • Open source origin model based on Keras which is trained with.
  • More language support (Chinese).

Thanks for third party lib in demo

Contact

  • 曹佳鑫 (tsao)An iOS developer with experience in deep learning living in Shanghai.
  • Pull requests and issues are welcome.
  • Mail:cjx5813@foxmail.com

License

ShowAndTell is available under the MIT license. See the LICENSE file for more info.

About

A Show And Tell implementation for iOS 11.0 based on CoreML

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp