ValueError:未知的初始值设定项:HeNormal

如何解决ValueError:未知的初始值设定项:HeNormal

我正在建立一个基于cnn的情绪检测模型。我已经在google colab上训练了模型,并尝试将这些权重加载到本地的jupyter机器中。这样做时,我得到以下错误堆栈:

self.parent.ids.lblA.text = "I am changed from btnA(which is in Table module)"

我的代码部分是:

ValueError                                Traceback (most recent call last)
<ipython-input-9-95fbe8e6b6b2> in <module>
     21 
     22 path = ""
---> 23 model = load_model(path)
     24 
     25 fcc_path = "Tools/haarcascade_frontalface_alt.xml"

<ipython-input-9-95fbe8e6b6b2> in load_model(path)
      9         json_file.close()
     10 
---> 11         model = model_from_json(loaded_model_json)
     12         model.load_weights(path + "model.h5")
     13         print("Loaded model from disk")

~\Anaconda3\lib\site-packages\tensorflow_core\python\keras\saving\model_config.py in model_from_json(json_string,custom_objects)
     94   config = json.loads(json_string)
     95   from tensorflow.python.keras.layers import deserialize  # pylint: disable=g-import-not-at-top
---> 96   return deserialize(config,custom_objects=custom_objects)

~\Anaconda3\lib\site-packages\tensorflow_core\python\keras\layers\serialization.py in deserialize(config,custom_objects)
    100       module_objects=globs,101       custom_objects=custom_objects,--> 102       printable_module_name='layer')

~\Anaconda3\lib\site-packages\tensorflow_core\python\keras\utils\generic_utils.py in deserialize_keras_object(identifier,module_objects,custom_objects,printable_module_name)
    189             custom_objects=dict(
    190                 list(_GLOBAL_CUSTOM_OBJECTS.items()) +
--> 191                 list(custom_objects.items())))
    192       with CustomObjectScope(custom_objects):
    193         return cls.from_config(cls_config)

~\Anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\sequential.py in from_config(cls,config,custom_objects)
    367     for layer_config in layer_configs:
    368       layer = layer_module.deserialize(layer_config,--> 369                                        custom_objects=custom_objects)
    370       model.add(layer)
    371     if not model.inputs and build_input_shape:

~\Anaconda3\lib\site-packages\tensorflow_core\python\keras\layers\serialization.py in deserialize(config,printable_module_name)
    191                 list(custom_objects.items())))
    192       with CustomObjectScope(custom_objects):
--> 193         return cls.from_config(cls_config)
    194     else:
    195       # Then `cls` may be a function returning a class.

~\Anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py in from_config(cls,config)
    592         A layer instance.
    593     """
--> 594     return cls(**config)
    595 
    596   def compute_output_shape(self,input_shape):

~\Anaconda3\lib\site-packages\tensorflow_core\python\keras\layers\convolutional.py in __init__(self,filters,kernel_size,strides,padding,data_format,dilation_rate,activation,use_bias,kernel_initializer,bias_initializer,kernel_regularizer,bias_regularizer,activity_regularizer,kernel_constraint,bias_constraint,**kwargs)
    489         activation=activations.get(activation),490         use_bias=use_bias,--> 491         kernel_initializer=initializers.get(kernel_initializer),492         bias_initializer=initializers.get(bias_initializer),493         kernel_regularizer=regularizers.get(kernel_regularizer),~\Anaconda3\lib\site-packages\tensorflow_core\python\keras\initializers.py in get(identifier)
    192     return None
    193   if isinstance(identifier,dict):
--> 194     return deserialize(identifier)
    195   elif isinstance(identifier,six.string_types):
    196     identifier = str(identifier)

~\Anaconda3\lib\site-packages\tensorflow_core\python\keras\initializers.py in deserialize(config,custom_objects)
    184       module_objects=module_objects,185       custom_objects=custom_objects,--> 186       printable_module_name='initializer')
    187 
    188 

~\Anaconda3\lib\site-packages\tensorflow_core\python\keras\utils\generic_utils.py in deserialize_keras_object(identifier,printable_module_name)
    178     config = identifier
    179     (cls,cls_config) = class_and_config_for_serialized_keras_object(
--> 180         config,printable_module_name)
    181 
    182     if hasattr(cls,'from_config'):

~\Anaconda3\lib\site-packages\tensorflow_core\python\keras\utils\generic_utils.py in class_and_config_for_serialized_keras_object(config,printable_module_name)
    163     cls = module_objects.get(class_name)
    164     if cls is None:
--> 165       raise ValueError('Unknown ' + printable_module_name + ': ' + class_name)
    166   return (cls,config['config'])
    167 

ValueError: Unknown initializer: HeNormal

希望您能找到解决我的问题的方法,并且过去几天一直停留在这里。预先感谢。

解决方法

您的推理环境中的 tensorflow/keras 版本似乎与您用于训练模型的版本不同。他们在较新版本中将 he_normal 更改为 HeNormal。

尝试以下操作,它应该让 tensorflow 引用正确的对象:

HeNormal = tf.keras.initializers.he_normal()
load_model= keras.models.load_model(your_model_path,custom_objects={'HeNormal': HeNormal},compile=False)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res