models icon indicating copy to clipboard operation
models copied to clipboard

unable to read mobilenet_v2 checkpoint(Top1-Imagenet 74.9)

Open deepdata-foundation opened this issue 8 years ago • 17 comments

What is the version of TF for read the mobilenet_v2 checkpoint

My version is TF 1.4.1

However, Unable to read the mobilenet_v2 checkpoint

deepdata-foundation avatar Mar 31 '18 06:03 deepdata-foundation

I met the problem on TensorFlow 1.4, too. I run the following code:

saver = tf.train.Saver(var_list=gvars)
saver.restore(sess, 'mobilenet_v2_1.4_224.ckpt')

I get the following error:

DataLossError (see above for traceback): Unable to read file (mobilenet_v2_1.4_224.ckpt.index). Perhaps the file is corrupt or was produced by a newer version of TensorFlow with format changes (failed to seek to header entry): corrupted compressed block contents
	 [[Node: save/RestoreV2 = RestoreV2[dtypes=[DT_INT32], _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_save/Const_0_0, save/RestoreV2/tensor_names, save/RestoreV2/shape_and_slices)]]

jihaonew avatar Mar 31 '18 07:03 jihaonew

+1

kecaiwu avatar Mar 31 '18 09:03 kecaiwu

+1. I am trying to training the whole mobilenet_v2 rather than re-tuning the checkpoint.

lyhcloud avatar Apr 01 '18 09:04 lyhcloud

I am getting error:

InvalidArgumentError (see above for traceback): Assign requires shapes of both tensors to match. lhs shape= [3,3,3,32] rhs shape= [3,3,3,48]

Tensorflow 1.7 Params:

--checkpoint_exclude_scopes=MobilenetV2/Logits
--trainable_scopes=MobilenetV2/Logits

smivv avatar Apr 05 '18 10:04 smivv

+1 cannot load mobilenet_v2_1.4 but can load mobilenet_v2_1.0, seems like 1.4 ckpt does not match the architecture of mobilenet_v2.py in the repo. maybe it has more conv channels, need to investigate mobilenet_v2_1.4's ckpt.

rickerliang avatar Apr 06 '18 10:04 rickerliang

+1 when I want to finetune mobilenet_v2_1.4_224_imageNet_pretrained on voc_aug, I got error as below:

INFO:tensorflow:Error reported to Coordinator: <class 'tensorflow.python.framework.errors_impl.InvalidArgumentError'>, Assign requires shapes of both tensors to match. lhs shape= [96] rhs shape= [136] [[Node: save/Assign_55 = Assign[T=DT_FLOAT, _class=["loc:@MobilenetV2/expanded_conv_11/project/BatchNorm/beta"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](MobilenetV2/expanded_conv_11/project/BatchNorm/beta, save/RestoreV2:55)]]

raninbowlalala avatar Apr 11 '18 07:04 raninbowlalala

@raninbowlalala You should set the num_classes=None when you calling the model mobilenet_v2, and then add a additionally fully_connected layer with you specified num_classes.

Shirhe-Lyh avatar Apr 15 '18 13:04 Shirhe-Lyh

In mobilenet_v2.py, depth_multiplier=1 for both mobilenet and mobilenet_base, you should change that to 1.4

@slim.add_arg_scope
def mobilenet_base(input_tensor, depth_multiplier=1.4, **kwargs):
  """Creates base of the mobilenet (no pooling and no logits) ."""
  return mobilenet(input_tensor,
                   depth_multiplier=depth_multiplier,
                   base_only=True, **kwargs)
@slim.add_arg_scope
def mobilenet(input_tensor,
              num_classes=1001,
              depth_multiplier=1.4,
              scope='MobilenetV2',
              conv_defs=None,
              finegrain_classification_mode=False,
              min_depth=None,
              divisible_by=None,
              **kwargs):

sid6641 avatar Apr 18 '18 15:04 sid6641

tf1.4.0 Unable to read file (mobilenet_v2_1.4_224.ckpt.index). Perhaps the file is corrupt or was produced by a newer version of TensorFlow with format changes (failed to seek to header entry): corrupted compressed block contents

suntim avatar May 21 '18 09:05 suntim

+1

I also got the following error info when loading mobilenet_v2_1.4_224.ckpt.index

tensorflow/core/framework/op_kernel.cc:1192] Data loss: Unable to read

file(pretrained/mobilenetv2/mobilenet_v2_1.4_224.ckpt.index). Perhaps the file 

is corrupt or was produced by newer version of TensorFlow with format changes

 (failed to seek to header entry): corrupted compressed block contents

I also changed the parameter depth_multiplier=1 to 1.4 in mobilenet_v2.py for both mobilenet and mobilenet_base, still no uses.

For previous tensor mismatch issue, I think changing the parameter works since I didn't see anymore, but the above corrupted error still remains and I think it's related to the file format or tensorflow version

deercoder avatar Jul 18 '18 19:07 deercoder

I got the same error when loading mobilenet_v2_1.4_224.ckpt.index to deeplab v3+, using mobilenet_v2 as backe bone. Inspired by @sid6641, i searched paramater depth_multiplier=1 and modified it to 1.4, but it didn't work , like @deercoder. I think the reason is old ckpt doesn't match the current one, I fix it by using mobilenet_v2_1.0_224.

pumpking404 avatar Aug 03 '18 02:08 pumpking404

@deercoder loading mobilenet_v2_1.4_224.ckpt instead of loading mobilenet_v2_1.4_224.ckpt.index

Jason-xin avatar Aug 22 '18 03:08 Jason-xin

@NxG1GnX mobilenet_v2_1.0_224??? Mine is mobilenet_v2_1.0_224.ckpt, which is the prefix of data/meta/index

Jason-xin avatar Aug 22 '18 03:08 Jason-xin

I still try to use mobilenet_v2_1.4_224.ckpt or mobilenet_v2_1.0_224.ckpt , but all fail.My tensorflow version is 1.4.0 ,maybe the version is too low , but I don't want to update. How to solve the question? error information is: DataLossError (see above for traceback): Unable to read file (/home/hanlab/zhangpeng/mobilenetV2/1.0/mobilenet_v2_1.0_224.ckpt.index). Perhaps the file is corrupt or was produced by a newer version of TensorFlow with format changes (failed to seek to header entry): corrupted compressed block contents [[Node: save/RestoreV2_4 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_save/Const_0_0, save/RestoreV2_4/tensor_names, save/RestoreV2_4/shape_and_slices)]]

Benzzzxxx avatar Sep 27 '18 09:09 Benzzzxxx

@NxG1GnX Are you sure that you can use mobilenet_v2_1.0_224.ckpt ?What's your tensorflow version?

Benzzzxxx avatar Sep 27 '18 09:09 Benzzzxxx

In mobilenet_v2.py, depth_multiplier=1 for both mobilenet and mobilenet_base, you should change that to 1.4

@slim.add_arg_scope
def mobilenet_base(input_tensor, depth_multiplier=1.4, **kwargs):
  """Creates base of the mobilenet (no pooling and no logits) ."""
  return mobilenet(input_tensor,
                   depth_multiplier=depth_multiplier,
                   base_only=True, **kwargs)
@slim.add_arg_scope
def mobilenet(input_tensor,
              num_classes=1001,
              depth_multiplier=1.4,
              scope='MobilenetV2',
              conv_defs=None,
              finegrain_classification_mode=False,
              min_depth=None,
              divisible_by=None,
              **kwargs):

In practice, I found that the divisible_by parameter is also important. You can try to set

divisible_by=8

if you failed to restore the ckpt. This setting makes the number of channels to be divisible by 8. And it is consistent with the number of channels in the provided ckpt. https://github.com/tensorflow/models/tree/master/research/slim/nets/mobilenet

mzhaoshuai avatar Apr 09 '19 07:04 mzhaoshuai

Hi There, We are checking to see if you still need help on this, as this seems to be considerably old issue. Please update this issue with the latest information, code snippet to reproduce your issue and error you are seeing. If we don't hear from you in the next 7 days, this issue will be closed automatically. If you don't need help on this issue any more, please consider closing this.

tensorflowbutler avatar Jan 29 '20 23:01 tensorflowbutler