import numpy as np
import keras
from keras.models import load_model
from keras_layers.keras_layer_AnchorBoxes import AnchorBoxes
from keras_loss_function.keras_ssd_loss import SSDLoss
ssd_loss = SSDLoss(neg_pos_ratio=3, alpha=1.0)
model = load_model('my_smodel.h5', custom_objects={'AnchorBoxes': AnchorBoxes,
'compute_loss': ssd_loss.compute_loss})
当我试图加载这个模型我得到这个错误,这个代码在python 3上运行但不在python 2上 . 我想在python 2中,因为我想将此模型转换为仅支持python 2的Coreml .
我使用pip安装了tensorflow,现在我试图通过源安装它 .
ImportError Traceback (most recent call last)
in ()
1 import numpy as np
----> 2 import keras
3 from keras.models import load_model
4 from keras_layers.keras_layer_AnchorBoxes import AnchorBoxes
5 from keras_loss_function.keras_ssd_loss import SSDLoss
build/bdist.linux-x86_64/egg/keras/__init__.py in ()
build/bdist.linux-x86_64/egg/keras/utils/__init__.py in ()
build/bdist.linux-x86_64/egg/keras/utils/conv_utils.py in ()
build/bdist.linux-x86_64/egg/keras/backend/__init__.py in ()
build/bdist.linux-x86_64/egg/keras/backend/tensorflow_backend.py in ()
/home/mohsin/coreml/lib/python2.7/site-packages/tensorflow/__init__.py in ()
21 from __future__ import print_function
22
---> 23 from tensorflow.python import *
24
25
/home/mohsin/coreml/lib/python2.7/site-packages/tensorflow/python/__init__.py in ()
47 _default_dlopen_flags = sys.getdlopenflags()
48 sys.setdlopenflags(_default_dlopen_flags | ctypes.RTLD_GLOBAL)
---> 49 from tensorflow.python import pywrap_tensorflow
50 sys.setdlopenflags(_default_dlopen_flags)
51
/home/mohsin/coreml/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py in ()
26 fp.close()
27 return _mod
---> 28 _pywrap_tensorflow = swig_import_helper()
29 del swig_import_helper
30 else:
/home/mohsin/coreml/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py in swig_import_helper()
22 if fp is not None:
23 try:
---> 24 _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
25 finally:
26 fp.close()
ImportError: /home/mohsin/coreml/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so: undefined symbol: PyUnicodeUCS4_AsUTF8String