Open la735681253 opened 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)
Convert the model from Caffe to IR format
mkdir -p $IR_DIR
mmtoir -f caffe -n $PATH_PROTOTXT -w $PATH_CAFFEMODEL --inputShape $INPUT_SHAPE -d $IR_DIR/$MODEL_NAME
Convert the model from IR to TensorFlow code snippet
mkdir -p $CONVERTED_MODEL_DIR
mmtocode -f tensorflow -n "$IR_DIR/$MODEL_NAME.pb" -w "$IR_DIR/$MODEL_NAME.npy" -d "$CONVERTED_MODEL_DIR/$MODEL_NAME.py"
After this step you probably will get the similar error Object arrays cannot be loaded when allow_pickle=False
. Now it happens because of np.load(file_name).item()
in generated
"$CONVERTED_MODEL_DIR/$MODEL_NAME.py"
file. Navigate to the error string and replace it with np.load(file_name, allow_pickle = True).item()
Convert the model from IR to TensorFlow model
mmtomodel -f tensorflow -in "$CONVERTED_MODEL_DIR/$MODEL_NAME.py" -iw "$IR_DIR/$MODEL_NAME.npy" -o "$CONVERTED_MODEL_DIR/$MODEL_NAME.ckpt" --dump_tag SERVING
P.S.: you can use --dump_tag TRAINING
instead --dump_tag SERVING
@juliagusak, Thank you very much for the detailed explanation!
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.
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