Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么在保存keras模型后更改类名?_Python_Class_Tensorflow_Keras_Tf.keras - Fatal编程技术网

Python 为什么在保存keras模型后更改类名?

Python 为什么在保存keras模型后更改类名?,python,class,tensorflow,keras,tf.keras,Python,Class,Tensorflow,Keras,Tf.keras,我使用tensorflow(2.0.0)编写了一个基本的keras模型(tf.keras._version=2.2.4-tf): 结果是 Python 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> exec

我使用tensorflow(2.0.0)编写了一个基本的keras模型(tf.keras._version=2.2.4-tf):

结果是

Python 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exec(open(r'C:\tmp\myPython\test_type_model.py').read())
2019-11-26 18:49:39.071088: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2019-11-26 18:49:39.574113: W tensorflow/python/util/util.cc:299] Sets are not currently considered sequences, but this may change in the future, so consider avoiding using them.
WARNING: Logging before flag parsing goes to stderr.
W1126 18:49:39.627490 11772 deprecation.py:506] From F:\Program Files\Python\lib\site-packages\tensorflow_core\python\ops\resource_variable_ops.py:1781: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.
Instructions for updating:
If using Keras pass *_constraint arguments to layers.
Model saved type :  <class 'tensorflow.python.keras.engine.sequential.Sequential'>
Model loaded type :  <class 'tensorflow.python.keras.saving.saved_model.load.Sequential'>
compare object model with loaded_model type :  False
compare object loaded_model with model type :  True
compare sublclass loaded_model and model type :  True
win32上的Python 3.6.6(v3.6.6:4cf1f54eb7,2018年6月27日,03:37:03)[MSC v.1900 64位(AMD64)] 有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。 >>>exec(打开(r'C:\tmp\myPython\test\u type\u model.py').read()) 2019-11-26 18:49:39.071088:I tensorflow/core/platform/cpu_feature_guard.cc:142]您的cpu支持未编译此tensorflow二进制文件以使用的指令:AVX2 2019-11-26 18:49:39.574113:W TunSoFrase/Python/UTIL/UTIL.CC:299)集合目前不被认为是序列,但是这在将来可能会改变,所以考虑避免使用它们。 警告:在标记解析转到stderr之前进行日志记录。 W1126 18:49:39.627490 11772 deprecation.py:506]来自F:\Program Files\Python\lib\site packages\tensorflow\u core\Python\ops\resource\u variable\u ops.py:1781:调用BaseSourceVariable。带有约束的\uuuuuu init\uuuuu(来自tensorflow.Python.ops.resource\u variable\u ops)已被弃用,将在未来版本中删除。 更新说明: 如果使用Keras,则将*\u约束参数传递到图层。 模型保存类型: 模型加载类型: 将对象模型与加载的模型类型进行比较:False 比较加载对象的\u模型与模型类型:True 比较加载的子类\u模型和模型类型:True
在tensorflow或keras文档中,tensorflow.python.keras.saving.saved_model.load.Sequential和tensorflow.python.keras.engine.Sequential.Sequential之间的区别在哪里?

这并不是一个正确的答案,但我想补充一下我在这个问题上的发现(这让我非常困惑):

  • 我找不到关于它的任何文档
  • 使用h5格式为我解决了这个问题:model.save('c:\tmp\oneuron.h5')
  • 更改的对象类型确实给我带来了问题,例如model.layers[i]。过滤器在保存和重新加载之前可以工作,但在保存和重新加载之后不能工作
我的tensorflow版本是2.1

Python 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exec(open(r'C:\tmp\myPython\test_type_model.py').read())
2019-11-26 18:49:39.071088: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2019-11-26 18:49:39.574113: W tensorflow/python/util/util.cc:299] Sets are not currently considered sequences, but this may change in the future, so consider avoiding using them.
WARNING: Logging before flag parsing goes to stderr.
W1126 18:49:39.627490 11772 deprecation.py:506] From F:\Program Files\Python\lib\site-packages\tensorflow_core\python\ops\resource_variable_ops.py:1781: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.
Instructions for updating:
If using Keras pass *_constraint arguments to layers.
Model saved type :  <class 'tensorflow.python.keras.engine.sequential.Sequential'>
Model loaded type :  <class 'tensorflow.python.keras.saving.saved_model.load.Sequential'>
compare object model with loaded_model type :  False
compare object loaded_model with model type :  True
compare sublclass loaded_model and model type :  True