can't import pretrained mobilenet model
I download mobilenet_v1_1.0_224_2017_06_14.tar.gz and untar it and then use the following code to import it.
import tensorflow as tf from tensorflow.contrib import layers with tf.Session() as sess: tf.contrib saver = tf.train.import_meta_graph('./tmp/mobilenet_v1_1.0_224.ckpt.meta')
However, I got the following error. Any idea why this error happens.
Traceback (most recent call last):
File "./restore.py", line 9, in
My tensorflow version: 1.1.0-rc1
Thanks,
same issue on mac, tf version 1.2.0
@korrawat , do you have any thoughts on what is causing this?
I'm also getting this on Ubuntu, TF 1.2.0.
As a work-around, I also tried to use the slim library definitions and restore the variables. I have been able to save (and test) frozen models for the 4 1.0 files, but on 0.75/0.50/0.25 models, I get errors (see this gist for all output) due to dimension mismatches, e.g.:
W tensorflow/core/framework/op_kernel.cc:1158] Invalid argument: Assign requires shapes of both tensors to match. lhs shape= [256] rhs shape= [64]
[[Node: save/Assign_92 = Assign[T=DT_FLOAT, _class=["loc:@MobilenetV1/Conv2d_5_pointwise/BatchNorm/moving_mean"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/gpu:0"](MobilenetV1/Conv2d_5_pointwise/BatchNorm/moving_mean, save/RestoreV2_92/_167)]]
The code that I used can be found at this gist (tested with Python 3 + TF 1.2.0). You just need to edit it to have the models_slim_dir variable to have the path to the models git repo.
EDIT: Nevermind, it looks like I was not passing in the depth_multiplier variable (I overlooked it, as there is no mechanism for it using nets_factory). I have updated the gist and it seems to work.
@aselle, I got the same error on Ubuntu, TF 1.2.0. I'm not really sure why the checkpoint files don't work either.
@korrawat , Is the current slim MobileNet code the same code that was used to create those checkpoints? Otherwise, I don't understand what could be the issue with my restoring code. If you have a chance to look at that, I'd appreciate it.
Looking into this.
To get rid of the SSTableReaderV2 op that doesn't exist in the open source TensorFlow, build a graph with logits, end_points = mobilenet_v1.mobilenet_v1(tf.placeholder(dtype=tf.float32, shape=(1, 224, 224, 3), name='image_tensor'), 1001) instead of importing from the checkpoint meta graph def with saver = tf.train.import_meta_graph('mobilenet_v1_1.0_224.ckpt.meta'). A complete example is in object_detection/exporter.py.
@futurely , Have you tried this approach with the non-1.0 MobileNets? I get errors due to incompatible dimensions (see my previous post for gist link).
EDIT: Nevermind, it looks like I was not passing in the depth_multiplier variable (I overlooked it, as there is no mechanism for it using nets_factory). I have updated the code and it seems to work.
Take a look #1702
After generating *.pb files by gist from @StanislawAntol and placing it to *.ckpt files I was able to load weight.
@NickShargan I have generated the *.pb file, what do you mean by placing it to the *.ckpt files and how did you do so?
Hi, I have the same error in ubuntu16.04, tensorflow1.2, have your guys fixed your problem?
Hi, I'am getting the same error on win10, tf 1.2. Anyone got a solution?
i have the same porblem~Anyone fixed it?
@StanislawAntol can you be more precise on the process you follow ?
@kmonachopoulos, I'm not sure how much more precise I can be than the gist posted above. You just need to edit it to have the models git repo and then run it.
Sorry, it was just a path error I missed, it is working, thanks
@kmonachopoulos, no worries. I guess I technically updated the code and hadn't editet the comment to reflect this. It's fixed now to be clearer.
@StanislawAntol Thanks for the gist code. So what are we supposed to do after generating the .pb files?
@amirjamez, It contains the model so you can load it, feed in input (i.e., images), and get classification results, e.g., something like this C++ code or this Python code.