加载H5模型时出现未知的图层错误

时间:2020-04-26 00:09:08

标签: python tensorflow keras-layer tf.keras

我从可教机器(https://teachablemachine.withgoogle.com/)训练了模型。当我尝试加载模型时,它给了我“ unknown layer:name”。

import tensorflow.python.keras
model = tensorflow.keras.models.load_model('keras_model.h5')

我查找了使用custom_objects的解决方案。所以我试着给我NameError:名称'名称'未定义。

import tensorflow.python.keras
C:\Users\Farhan\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\framework\dtypes.py:469: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
C:\Users\Farhan\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\framework\dtypes.py:470: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
C:\Users\Farhan\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\framework\dtypes.py:471: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
C:\Users\Farhan\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\framework\dtypes.py:472: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
C:\Users\Farhan\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\framework\dtypes.py:473: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
C:\Users\Farhan\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\framework\dtypes.py:476: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
>>> model = tensorflow.keras.models.load_model('keras_model.h5', custom_objects={'name': name})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'name' is not defined

有一种解决方案,指示从文件导入层“名称”。然后使用它。但是可教的机器没有给我任何文件。只是保存的模型。可以有人帮我

0 个答案:

没有答案