Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrain image detection with MobileNet

Several ways of retraining MobileNet for use with Tensorflow.js have failed for me. Is there any way to use a retrained model with Tensorflow.js?

Both using the modern, hub-based tutorial, as well as using retrain.py seem to fail.

  • Convert output of retrain.py to tensorflow.js
  • Error converting keras model to tfjs: duplicate weight name Variable

as well as some other open questions

  • Retrain an Image Classifier in tensorflow js
  • Loading of mobilenet v2 works, but pretrained mobilenet v2 fails
  • Can't convert TensorFlow saved model to tfjs_layers_model webmodel

The top two other questions show the code that failed in both instances, both are unsolved.

The aim is to load the mobilenet, retrain using custom data, and use it in Tensorflow.js. Following both tutorials seem to fail. Could this be done inside node.js? Is there another way? Where did I make mistakes (or is the software unable to use retrained models)? How can this work?

EDITs: latest github issue and one more question

like image 503
serv-inc Avatar asked Apr 25 '19 12:04

serv-inc


People also ask

What data augmentation is included in the MobileNet model configuration file?

The model configuration file with MobileNet includes two types of data augmentation at training time: random crops, and random horizontal and vertical flips The model configuration file default batch size is 12 and the learning rate is 0.0004. Adjust these based on your training results.

What is MobileNet and how it works?

Hence, here comes in action what is known as MobileNet. Mobilenet is a model which does the same convolution as done by CNN to filter images but in a different way than those done by the previous CNN. It uses the idea of Depth convolution and point convolution which is different from the normal convolution as done by normal CNNs.

Why should you retrain the object detection model in TensorFlow?

This time around I wanted to spend my week retraining the object detection model and writing up a guide so that other developers can do the same thing. TensorFlow’s object detection technology can provide huge opportunities for mobile app development companies and brands alike to use a range of tools for different purposes.

How do you train an object detection model?

To train an object detection model from scratch will require long hours of model training. To save time, the simplest approach would be to use an already trained model and retrain it to detect your custom objects. This process is called “ transfer learning”. Why mobilenetV2? Object detection model performance continues to improve.


2 Answers

I encountered the same problem and it seems that we use the wrong method. There are loadGraphModel for TF converted models and loadLayersModel for Keras ones my comment about the issue

like image 101
Mahalov Ivan Avatar answered Sep 22 '22 09:09

Mahalov Ivan


The retrain.py python script does not generate a saved model, it actually generates a frozen graph model. That is why you cannot convert it using the tfjs 1.x converter. You need to use tfjs 0.8.5 pip to convert. Also, the output node name is different from the mobilenet model graph, it is 'final_result' for retrained graph.

To convert it you need to use the tensorflowjs 0.8.5 pip:

  • use virtualenv to create an empty env.
  • pip install tensorflowjs==0.8.5
  • run the converter
tensorflowjs_converter \
  --input_format=tf_frozen_model \
  --output_node_names='final_result' \
  --output_json=true /tmp/output_graph.pb \ /tmp/web_model

This should give you something like the following:

ls /tmp/web_model/
group1-shard10of21  group1-shard14of21  group1-shard18of21  group1-shard21of21  group1-shard5of21  group1-shard9of21
group1-shard11of21  group1-shard15of21  group1-shard19of21  group1-shard2of21   group1-shard6of21  model.json
group1-shard12of21  group1-shard16of21  group1-shard1of21   group1-shard3of21   group1-shard7of21
group1-shard13of21  group1-shard17of21  group1-shard20of21  group1-shard4of21   group1-shard8of21
like image 35
Ping Yu Avatar answered Sep 18 '22 09:09

Ping Yu