训练LSTM模型时tensorflow.python.framework.errors_impl.AlreadyExistsError

如何解决训练LSTM模型时tensorflow.python.framework.errors_impl.AlreadyExistsError

在使用LSTM给出一系列单词的情况下,我正在尝试在keras中创建一个猜测下一个单词的机器学习模型。这是我的模型的代码:

gen=Sequential()
gen.add(Embedding(vocab_size,embed_dim))
gen.add(LSTM(vocab_size,activation='softmax'))
gen.compile(loss='categorical_crossentropy',optimizer='adam')
gen.summary()
(X_train,X_test,Y_train,Y_test)=train_test_split(X,Y,test_size=.2)
gen.fit(X_train,validation_data=(X_test,Y_test),batch_size=batch_size,epochs=epochs)

我的X数据是填充整数数组的数组,例如:[0,59,73,4],而我的Y是一个热向量,其长度为我的唱头大小(在这种情况下为1994)。运行上面的代码将创建以下输出:

2020-08-23 11:19:34.390012: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not 

load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
2020-08-23 11:19:34.391222: E tensorflow/stream_executor/cuda/cuda_driver.cc:313] failed call to cuInit: UNKNOWN ERROR (303)
2020-08-23 11:19:34.405184: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: LAPTOP-J9AD5M4U
2020-08-23 11:19:34.406474: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: LAPTOP-J9AD5M4U
2020-08-23 11:19:34.407916: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2020-08-23 11:19:34.695283: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x20c4fc4a980 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-08-23 11:19:34.696499: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host,Default Version
Model: "sequential"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
embedding (Embedding)        (None,None,32)          75040     
_________________________________________________________________
lstm (LSTM)                  (None,2345)              22305640  
=================================================================
Total params: 22,380,680
Trainable params: 22,680
Non-trainable params: 0
_________________________________________________________________
2020-08-23 11:20:30.730043: W tensorflow/core/framework/op_kernel.cc:1753] OP_REQUIRES failed at variable_ops.cc:104 : Already exists: Resource __per_step_0/gradient_tape/sequential/lstm/while/sequential/lstm/while_grad/body/_354/gradients/AddN_6/tmp_var/struct tensorflow::TemporaryVariableOp::TmpVar
2020-08-23 11:20:30.943137: W tensorflow/core/framework/op_kernel.cc:1753] OP_REQUIRES failed at variable_ops.cc:104 : Already exists: Resource __per_step_0/gradient_tape/sequential/lstm/while/sequential/lstm/while_grad/body/_354/gradients/AddN_6/tmp_var/struct tensorflow::TemporaryVariableOp::TmpVar
2020-08-23 11:20:31.469228: W tensorflow/core/framework/op_kernel.cc:1753] OP_REQUIRES failed at variable_ops.cc:104 : Already exists: Resource __per_step_0/gradient_tape/sequential/lstm/while/sequential/lstm/while_grad/body/_354/gradients/AddN_6/tmp_var/struct tensorflow::TemporaryVariableOp::TmpVar
2020-08-23 11:20:32.787365: W tensorflow/core/framework/op_kernel.cc:1753] OP_REQUIRES failed at variable_ops.cc:104 : Already exists: Resource __per_step_0/gradient_tape/sequential/lstm/while/sequential/lstm/while_grad/body/_354/gradients/AddN_6/tmp_var/struct tensorflow::TemporaryVariableOp::TmpVar
2020-08-23 11:20:34.014073: W tensorflow/core/framework/op_kernel.cc:1753] OP_REQUIRES failed at variable_ops.cc:104 : Already exists: Resource __per_step_0/gradient_tape/sequential/lstm/while/sequential/lstm/while_grad/body/_354/gradients/AddN_6/tmp_var/struct tensorflow::TemporaryVariableOp::TmpVar
2020-08-23 11:20:34.752033: W tensorflow/core/framework/op_kernel.cc:1753] OP_REQUIRES failed at variable_ops.cc:104 : Already exists: Resource __per_step_0/gradient_tape/sequential/lstm/while/sequential/lstm/while_grad/body/_354/gradients/AddN_6/tmp_var/struct tensorflow::TemporaryVariableOp::TmpVar
2020-08-23 11:20:35.980107: W tensorflow/core/framework/op_kernel.cc:1753] OP_REQUIRES failed at variable_ops.cc:104 : Already exists: Resource __per_step_0/gradient_tape/sequential/lstm/while/sequential/lstm/while_grad/body/_354/gradients/AddN_6/tmp_var/struct tensorflow::TemporaryVariableOp::TmpVar
2020-08-23 11:20:36.790928: W tensorflow/core/framework/op_kernel.cc:1753] OP_REQUIRES failed at variable_ops.cc:104 : Already exists: Resource __per_step_0/gradient_tape/sequential/lstm/while/sequential/lstm/while_grad/body/_354/gradients/AddN_6/tmp_var/struct tensorflow::TemporaryVariableOp::TmpVar
2020-08-23 11:20:37.396431: W tensorflow/core/framework/op_kernel.cc:1753] OP_REQUIRES failed at variable_ops.cc:104 : Already exists: Resource __per_step_0/gradient_tape/sequential/lstm/while/sequential/lstm/while_grad/body/_354/gradients/AddN_6/tmp_var/struct tensorflow::TemporaryVariableOp::TmpVar
2020-08-23 11:20:38.314946: W tensorflow/core/framework/op_kernel.cc:1753] OP_REQUIRES failed at variable_ops.cc:104 : Already exists: Resource __per_step_0/gradient_tape/sequential/lstm/while/sequential/lstm/while_grad/body/_354/gradients/AddN_6/tmp_var/struct tensorflow::TemporaryVariableOp::TmpVar
2020-08-23 11:20:39.111772: W tensorflow/core/framework/op_kernel.cc:1753] OP_REQUIRES failed at variable_ops.cc:104 : Already exists: Resource __per_step_0/gradient_tape/sequential/lstm/while/sequential/lstm/while_grad/body/_354/gradients/AddN_6/tmp_var/struct tensorflow::TemporaryVariableOp::TmpVar
2020-08-23 11:20:39.859069: W tensorflow/core/framework/op_kernel.cc:1753] OP_REQUIRES failed at variable_ops.cc:104 : Already exists: Resource __per_step_0/gradient_tape/sequential/lstm/while/sequential/lstm/while_grad/body/_354/gradients/AddN_6/tmp_var/struct tensorflow::TemporaryVariableOp::TmpVar
2020-08-23 11:20:40.938812: W tensorflow/core/framework/op_kernel.cc:1753] OP_REQUIRES failed at variable_ops.cc:104 : Already exists: Resource __per_step_0/gradient_tape/sequential/lstm/while/sequential/lstm/while_grad/body/_354/gradients/AddN_6/tmp_var/struct tensorflow::TemporaryVariableOp::TmpVar
2020-08-23 11:20:42.485426: W tensorflow/core/framework/op_kernel.cc:1753] OP_REQUIRES failed at variable_ops.cc:104 : Already exists: Resource __per_step_0/gradient_tape/sequential/lstm/while/sequential/lstm/while_grad/body/_354/gradients/AddN_6/tmp_var/struct tensorflow::TemporaryVariableOp::TmpVar
2020-08-23 11:20:43.183461: W tensorflow/core/framework/op_kernel.cc:1753] OP_REQUIRES failed at variable_ops.cc:104 : Already exists: Resource __per_step_0/gradient_tape/sequential/lstm/while/sequential/lstm/while_grad/body/_354/gradients/AddN_6/tmp_var/struct tensorflow::TemporaryVariableOp::TmpVar
Traceback (most recent call last):
  File "C:\Users\jsmith\Desktop\Code\JohnWorkspaces\Machine_Learning\Next Word\train.py",line 45,in <module>
    gen.fit(X_train,epochs=epochs)
  File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py",line 66,in _method_wrapper
    return method(self,*args,**kwargs)
  File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py",line 848,in fit
    tmp_logs = train_function(iterator)
  File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\eager\def_function.py",line 580,in __call__
    result = self._call(*args,**kwds)
  File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\eager\def_function.py",line 644,in _call
    return self._stateless_fn(*args,**kwds)
  File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\eager\function.py",line 2420,in __call__
    return graph_function._filtered_call(args,kwargs)  # pylint: disable=protected-access
  File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\eager\function.py",line 1665,in _filtered_call
    self.captured_inputs)
  File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\eager\function.py",line 1746,in _call_flat
    ctx,args,cancellation_manager=cancellation_manager))
  File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\eager\function.py",line 598,in call
    ctx=ctx)
  File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\eager\execute.py",line 60,in quick_execute
    inputs,attrs,num_outputs)
tensorflow.python.framework.errors_impl.AlreadyExistsError:  Resource __per_step_0/gradient_tape/sequential/lstm/while/sequential/lstm/while_grad/body/_354/gradients/AddN_6/tmp_var/struct tensorflow::TemporaryVariableOp::TmpVar
     [[{{node gradient_tape/sequential/lstm/while/sequential/lstm/while_grad/body/_354/gradients/AddN_6/tmp_var}}]] [Op:__inference_train_function_3777]

Function call stack:
train_function

有时它会分批训练,然后得到错误,而其他时候它会在根本不进行任何学习之前生成错误。我不知道它是否与LSTM的输入和输出形状有关,但是我希望这是否会在gen.compile而不是gen.fit上出现。

解决方法

所以我只是尝试了一个实验,发现它是LSTM的输出形状,并具有较小的输出长度,然后使用密集层进行扩展可以消除错误。

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

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地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-