models icon indicating copy to clipboard operation
models copied to clipboard

can't import pretrained mobilenet model

Open kaishijeng opened this issue 9 years ago • 32 comments

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 saver = tf.train.import_meta_graph('./tmp/mobilenet_v1_1.0_224.ckpt.meta') File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1683, in import_meta_graph **kwargs) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/meta_graph.py", line 499, in import_scoped_meta producer_op_list=producer_op_list) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/importer.py", line 280, in import_graph_def raise ValueError('No op named %s in defined operations.' % node.op) ValueError: No op named SSTableReaderV2 in defined operations.

My tensorflow version: 1.1.0-rc1

Thanks,

kaishijeng avatar Jun 15 '17 16:06 kaishijeng

same issue on mac, tf version 1.2.0

yan7109 avatar Jun 15 '17 21:06 yan7109

@korrawat , do you have any thoughts on what is causing this?

aselle avatar Jun 15 '17 23:06 aselle

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.

StanislawAntol avatar Jun 16 '17 01:06 StanislawAntol

@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 avatar Jun 16 '17 12:06 korrawat

@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.

StanislawAntol avatar Jun 16 '17 18:06 StanislawAntol

Looking into this.

sguada avatar Jun 16 '17 22:06 sguada

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 avatar Jun 20 '17 09:06 futurely

@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.

StanislawAntol avatar Jun 20 '17 14:06 StanislawAntol

Take a look #1702

sguada avatar Jun 20 '17 17:06 sguada

After generating *.pb files by gist from @StanislawAntol and placing it to *.ckpt files I was able to load weight.

NickShargan avatar Jun 26 '17 12:06 NickShargan

@NickShargan I have generated the *.pb file, what do you mean by placing it to the *.ckpt files and how did you do so?

MilPat555 avatar Jul 07 '17 17:07 MilPat555

Hi, I have the same error in ubuntu16.04, tensorflow1.2, have your guys fixed your problem?

KeyKy avatar Jul 14 '17 02:07 KeyKy

Hi, I'am getting the same error on win10, tf 1.2. Anyone got a solution?

moniqueexner avatar Aug 11 '17 10:08 moniqueexner

i have the same porblem~Anyone fixed it?

xweihithub avatar Aug 16 '17 12:08 xweihithub

@StanislawAntol can you be more precise on the process you follow ?

kmonachopoulos avatar Aug 24 '17 16:08 kmonachopoulos

@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.

StanislawAntol avatar Aug 24 '17 16:08 StanislawAntol

Sorry, it was just a path error I missed, it is working, thanks

kmonachopoulos avatar Aug 24 '17 16:08 kmonachopoulos

@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 avatar Aug 24 '17 16:08 StanislawAntol

@StanislawAntol Thanks for the gist code. So what are we supposed to do after generating the .pb files?

amirjamez avatar Sep 08 '17 23:09 amirjamez

@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.

StanislawAntol avatar Sep 09 '17 00:09 StanislawAntol