ry / tensorflow-resnet

ResNet model in TensorFlow
MIT License
1.66k stars 625 forks source link

is there anyone have successfully load the pretrained model in code? #43

Open Yiman-GO opened 6 years ago

Yiman-GO commented 6 years ago

is there anyone have successfully load the pretrained model in code? I have no idea about it. I have tried : saver1 = tf.train.import_meta_graph(pretrained_meta) saver1.restore(sess, pretrained_ckpt) but it tells me that "At least two variables have the same name" if you have loaded successfully, please tell me your method. I will appreciate it.

GabrielXia commented 6 years ago

Hi @Yiman-GO, I tried something just like you did

with tf.Session() as sess:
    saver = tf.train.import_meta_graph('ResNet-L152.meta')
    saver.restore(sess, "ResNet-L152.ckpt")

And it worked fine, hope it helps !

Yiman-GO commented 6 years ago

@GabrielXia I tried but it doesn't work. Can I have a look at your code? I am confused where to add the code. Also, have you had an implementation on your own data successfully? I abandoned the pretrained model but! it doesn't work. it said that loss is nan. I have no idea about it. Thank you very much.

cardwing commented 6 years ago

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.

SongleChen2015 commented 5 years ago

@cardwing can you tell me where i can download 3D ResNet-50 model, thanks.

cardwing commented 5 years ago

@SongleChen2015, the following URL stores the model of 3d resnet-50, please check. https://drive.google.com/open?id=1WkNtPNqf7-O1-RvXj4auWTH6OYqA2QKG

SongleChen2015 commented 5 years ago

@cardwing I have downloaded the 3d resnet-50 model, thanks. Can you show me an example about how to define a 3d renset-50 network by using tensorflow ? Thanks again.

berylyellow commented 5 years ago

Hi @Yiman-GO, I tried something just like you did

with tf.Session() as sess:
    saver = tf.train.import_meta_graph('ResNet-L152.meta')
    saver.restore(sess, "ResNet-L152.ckpt")

And it worked fine, hope it helps !

When I do this, get: ValueError: At least two variables have the same name: fc/biases How to solve it?