microsoft / MMdnn

MMdnn is a set of tools to help users inter-operate among different deep learning frameworks. E.g. model conversion and visualization. Convert models between Caffe, Keras, MXNet, Tensorflow, CNTK, PyTorch Onnx and CoreML.
MIT License
5.8k stars 965 forks source link

when i caffe convert tensorflow,the error accur #681

Open la735681253 opened 5 years ago

la735681253 commented 5 years ago

Platform (like ubuntu 16.04/win10): 16.04

Python version: 3.6

Source framework with version (like Tensorflow 1.4.1 with GPU):caffe 1.0

Destination framework with version (like CNTK 2.3 with GPU): tensorflow 1.4

Pre-trained model path (webpath or webdisk path):

Running scripts: mmconvert -sf caffe -in deploy_vgg16_places365.prototxt -iw vgg16_places365.caffemodel -df tensorflow -om places365_tf.npy

Traceback (most recent call last): File "/home/liang/anaconda3/envs/caffe/lib/python3.6/site-packages/mmdnn/conversion/common/DataStructure/emitter.py", line 36, in _load_weights self.weights_dict = np.load(file_name).item() File "/home/liang/anaconda3/lib/python3.6/site-packages/numpy/lib/npyio.py", line 447, in load pickle_kwargs=pickle_kwargs) File "/home/liang/anaconda3/lib/python3.6/site-packages/numpy/lib/format.py", line 696, in read_array raise ValueError("Object arrays cannot be loaded when " ValueError: Object arrays cannot be loaded when allow_pickle=False

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/liang/anaconda3/envs/caffe/bin/mmconvert", line 11, in sys.exit(_main()) File "/home/liang/anaconda3/envs/caffe/lib/python3.6/site-packages/mmdnn/conversion/_script/convert.py", line 108, in _main ret = IRToCode._convert(code_args) File "/home/liang/anaconda3/envs/caffe/lib/python3.6/site-packages/mmdnn/conversion/_script/IRToCode.py", line 26, in _convert emitter = TensorflowEmitter((args.IRModelPath, args.IRWeightPath)) File "/home/liang/anaconda3/envs/caffe/lib/python3.6/site-packages/mmdnn/conversion/tensorflow/tensorflow_emitter.py", line 66, in init self._load_weights(model[1]) File "/home/liang/anaconda3/envs/caffe/lib/python3.6/site-packages/mmdnn/conversion/common/DataStructure/emitter.py", line 38, in _load_weights self.weights_dict = np.load(file_name, encoding='bytes').item() File "/home/liang/anaconda3/lib/python3.6/site-packages/numpy/lib/npyio.py", line 447, in load pickle_kwargs=pickle_kwargs) File "/home/liang/anaconda3/lib/python3.6/site-packages/numpy/lib/format.py", line 696, in read_array raise ValueError("Object arrays cannot be loaded when " ValueError: Object arrays cannot be loaded when allow_pickle=False

juliagusak commented 5 years ago

Hi @la735681253 , @rainLiuplus

the cause of this problem is overviewed here. In your case, if you did nothing with numpy version

Firstly, navigate to "/home/liang/anaconda3/envs/caffe/lib/python3.6/site-packages/mmdnn/conversion/common/DataStructure/emitter.py" and replace line 36 self.weights_dict = np.load(file_name).item() with self.weights_dict = np.load(file_name, allow_pickle = True).item()

Secondly, perform 3-step conversion instead 1-step:

Let IR_DIR will be a repo to store IR representation of the model and CONVERTED_MODEL_DIR - a repo to store TensorFlow model. MODEL_NAME is a name you use for the model ( my_vgg16, for example)

P.S.: you can use --dump_tag TRAINING instead --dump_tag SERVING

rainLiuplus commented 5 years ago

@juliagusak, Thank you very much for the detailed explanation!

bersbersbers commented 5 years ago

I suggest to rename this issue to "Object arrays cannot be loaded when allow_pickle=False", which will occur for many people who upgraded to numpy>=1.16.3 (where the default allow_pickle=True has been changed to allow_pickle=False). By the way, @rainLiuplus's commit above just fails in two Python 2.7 tests - if that could be fixed, that issue would be gone. Until then, installing numpy==1.16.2 is a workaround.