Skip to content

iamukasa/hot_not

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Building our own model

Creating a CNN from Scratch

Image Classifier through transfer learning

A Simple transfer learning with an Inception v3 and Imagenet architecture model which displays summaries in TensorBoard.

This example shows how to take a Inception v3 architecture model trained on ImageNet images, and train a new top layer that can recognize other classes of images.

The top layer receives as input a 2048-dimensional vector for each image. We train a softmax layer on top of this representation. Assuming the softmax layer contains N labels, this corresponds to learning N + 2048*N model parameters corresponding to the learned biases and weights.

Requirements

Dependencies

To install dependenxies you need to run

pip install -r requirements.txt

##Example

Here's an example, which assumes you have a folder containing class-named subfolders, each full of images for each label. The example folder flower_photos should have a structure like this:

~/data/hot_dog/photo1.jpg ~/data/hot_dog/photo2.jpg ... ~/data/not_hot_dog/anotherphoto77.jpg ~/data/not_hot_dog/somepicture.jpg ...

The subfolder names are important, since they define what label is applied to each image, but the filenames themselves don't matter. Once your images are prepared, you can run the training with a command like this:

python retrain.py --model_dir ./inception --image_dir data

Visualisation

To use with TensorBoard:

By default, this script will log summaries to /tmp/retrain_logs directory

Visualize the summaries with this command:

Inception

tensorboard --logdir /ouput/retrain_logs

mobilenets

tensorboard --logdir /tmp/retrain_logs

Testing

Inception

python retrain_model_classifier.py data/hot_dog/3742819.jpg

mobilenets

python label_image.py --image=data/hot_dog/3742819.jpg --graph=output/retrained_graph.pb --labels=output/retrained_labels.txt

retraining mobilenets

python retrain.py
--bottleneck_dir=output/bottlenecks
--how_many_training_steps=4000
--output_graph=output/retrained_graph.pb
--output_labels=output/retrained_labels.txt
--image_dir=data

##retraning inception sudo python retrain.py --image_dir data ./Inception

Converting to tflite inception

toco
--input_file=ouput/output_graph.pb
--output_file=ouput/output_graph.tflite
--input_format=TENSORFLOW_GRAPHDEF
--output_format=TFLITE
--input_shape=1,2048,2048,3
--input_array=input
--output_array=final_result
--inference_type=FLOAT
--input_data_type=FLOAT
--allow_custom_ops

Converting to tflite mobilenets

toco \
  --input_file=output/retrained_graph.pb \
  --output_file=output/output_graph.tflite \
  --input_format=TENSORFLOW_GRAPHDEF \
  --output_format=TFLITE \
  --input_shape=1,224,224,3 \
  --input_array=input \
  --output_array=final_result \
  --inference_type=FLOAT \
  --input_data_type=FLOAT\
  --allow_custom_ops

About

droidcon.co.ke talk

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published