hellochick / PSPNet-tensorflow

TensorFlow-based implementation of "Pyramid Scene Parsing Network".
326 stars 123 forks source link

How to generate ckpt pre-train model from caffemodel? #12

Open John1231983 opened 6 years ago

John1231983 commented 6 years ago

Hello, I was successful to achieve the performance as your report. I was download the PSPNet caffe and build with cudnn 5.0.

Then I run the code

python convert.py ./pspnet101_cityscapes_713.prototxt --caffemodel ./pspnet101_cityscapes.caffemodel --data-output-path ./pspnet-init.ckpt

However, I got the error as bellow. Did you have same error when you generate the cpkt file? Thanks

caffe-tensorflow/kaffe/tensorflow/transformer.py", line 242, in load
    NodeKind.BatchNorm]),
AttributeError: type object 'NodeKind' has no attribute 'BatchNorm'

Note that, I also changed the layers.py as below because the original code used name as BatchNorm

'BN': shape_identity,
'Interp': shape_identity,
YanZhiyuan0918 commented 6 years ago

Hello John! I have the same problem with you. Do you solve the problem?

YanZhiyuan0918 commented 6 years ago

@John1231983

John1231983 commented 6 years ago

@YanZhiyuan0918: Please look at the solution at https://github.com/Vladkryvoruchko/PSPNet-Keras-tensorflow

Let me know if you have any problem

YanZhiyuan0918 commented 6 years ago

@John1231983 Thanks a lot for advice. When I try to directly use the .npy model provided by [(https://github.com/Vladkryvoruchko/PSPNet-Keras-tensorflow)] to convert to .ckpt model, I run the code: python npy2ckpt.py ./model/pspnet101_cityscapes.npy --save-dir=./model/

then I have the problem as follow: ValueError: Variable conv4_17_3x3_bn/mean does not exist, or was not created with tf.get_variable(). Did you mean to set reuse=None in VarScope?

Do you know this problem?

John1231983 commented 6 years ago

OK. I see. I meet the problem and I need to used other code to convert npy2ckpt in the https://github.com/DrSleep/tensorflow-deeplab-resnet/tree/master/kaffe

YanZhiyuan0918 commented 6 years ago

Yes, I think so. The code npy2ckpt.py I used is also from https://github.com/DrSleep/tensorflow-deeplab-resnet . I think there is something unmatched in it .

John1231983 commented 6 years ago

@YanZhiyuan0918: have you solve the problem? Thanks

YanZhiyuan0918 commented 6 years ago

@John1231983 Not yet. Maybe we can ask for @hellochick for help.

hellochick commented 6 years ago

Hey @John1231983 @YanZhiyuan0918 , I only transformed the weights, and handcraft the model. So I did not use the Caffe - Tensorflow code to generate model.py. Also, when you try to load the weights, you should care about the mismatching of variable name, such as gamma and scale in batch normalization layer.

shipengai commented 6 years ago

Hey@hellochick , when train from scratch on ade20k dataset, we first need to restore pre-trained model such as resnet-50?