tensorflow-resnet icon indicating copy to clipboard operation
tensorflow-resnet copied to clipboard

image classification using resnet pre-trained

Open monajalal opened this issue 7 years ago • 12 comments

hey, what command should I run to do a classification or object recognition on a pre-trained model given to us in the torrent file?

[jalal@scc-c01 MHRN]$ tree tensorflow-resnet-pretrained-20160509
tensorflow-resnet-pretrained-20160509
|-- ResNet-L101.ckpt
|-- ResNet-L101.meta
|-- ResNet-L152.ckpt
|-- ResNet-L152.meta
|-- ResNet-L50.ckpt
`-- ResNet-L50.meta

0 directories, 6 files
[jalal@scc-c01 MHRN]$ tree tensorflow-resnet
tensorflow-resnet
|-- LICENSE
|-- README.md
|-- __init__.py
|-- config.py
|-- convert.py
|-- data
|   |-- ResNet-101-deploy.prototxt
|   |-- ResNet-152-deploy.prototxt
|   |-- ResNet-50-deploy.prototxt
|   |-- ResNet_mean.binaryproto
|   |-- cat.jpg
|   `-- tensorflow-resnet-pretrained-20160509.tar.gz.torrent
|-- forward.py
|-- image_processing.py
|-- resnet.py
|-- resnet_train.py
|-- synset.py
|-- train_cifar.py
`-- train_imagenet.py

1 directory, 18 files

monajalal avatar Nov 05 '17 20:11 monajalal

If you use tensorflow, then you should first build the graph and then load the pre-trained weight (tf.restore). Besides, the pre-trained model is a old checkpoint format (V1) as there is no .index and .data-00000-of-00001 file. I am currently training the ResNet50 and I will provide more info as the experiment proceeds.

cardwing avatar Dec 13 '17 06:12 cardwing

@cardwing hello, buddy. have you finished training the ResNet-50 yet? I found the pretrained model @ry provided can not be loaded, because i'm receiving this error message. can you help me? ValueError: At least two variables have the same name: scale5/block1/a/weights

LvJC avatar Dec 31 '17 07:12 LvJC

You should have a look on the variable name of ry's pre-trained model. Then, you should use the same variable name and this problem should be fixed.

cardwing avatar Jan 06 '18 04:01 cardwing

@cardwing where can I find the variable name list of ry's pre-trained model? thx

LvJC avatar Jan 07 '18 14:01 LvJC

@LvJC I met this problem too. Have you solved this problem? If have, please tell me. Thanks~

Yiman-GO avatar Feb 01 '18 03:02 Yiman-GO

@Yimian-Go sorry buddy. Could you please describe your problems? Or you just want to get the variable names in ry's checkpoints?

LvJC avatar Feb 01 '18 03:02 LvJC

@Yiman-GO sorry this is you

LvJC avatar Feb 01 '18 03:02 LvJC

@LvJC I want to use the pretrained model 'res50', so i use: saver = tf.train.import_meta_graph(pretrained_meta) saver.restore(sess, pretrained_ckpt)

Then it told me that the first sentence lead to :'ValueError: At least two variables have the same name: scale1/gamma'. [the name changed everytime]. I wanna know that whether my import is true or notand how to solve this problem. Thank you very much!

Yiman-GO avatar Feb 01 '18 08:02 Yiman-GO

@Yiman-GO Actually I can't find the .meta file, so I rebuild the graph of ry. And restore the Resnet-50 checkpoint. And I think you can have a try of my method. And if you met other problems, welcome to communicate.

LvJC avatar Feb 01 '18 14:02 LvJC

@LvJC ok. I will try it later. Now, I met a new problem. I converted my data to the byte(same with cifar10), but when i start to train, it told that loss_ is nan(from the 0 step). It's strange. Have you met with this problem?

Yiman-GO avatar Feb 02 '18 12:02 Yiman-GO

The following code works for me where I load the weight of 2D ResNet-50 model into 3D ResNet-50 model: with tf.Session() as sess: # build 3D ResNet-50 saver = tf.train.import_meta_graph('/DATA/houyn/pre-trained-models/models/ResNet-L50.meta') saver.restore(sess, '/DATA/houyn/pre-trained-models/models/ResNet-L50.ckpt') var_list = saver._var_list value=[] for i in range(265): tmp = sess.run(var_list[i], feed_dict={}) if tmp.shape[0] < 10: tmp = [tmp / 1.0 / tmp.shape[0] for _ in range(tmp.shape[0])] tmp = np.stack(tmp, axis=0) value.append(tmp) You can use PyCharm to view the variable values and its names in the debug mode.

cardwing avatar Mar 25 '18 09:03 cardwing

The variable name is stored in saver._var_list.

cardwing avatar Mar 25 '18 09:03 cardwing