Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Value passed to parameter 'shape' has DataType float32 not in list of allowed values: int32, int64 #4

Open
FankLi opened this issue Jul 6, 2019 · 7 comments

Comments

@FankLi
Copy link

FankLi commented Jul 6, 2019

运行这个(021-文章标题的自动生成.py)的时候报错,如题
我的环境是python3.6,tensorflow==1.8.0,keras==2.2.4
期待你的回复,谢谢

@FankLi
Copy link
Author

FankLi commented Jul 6, 2019

是运行到这一行报的错:

编码 两层双向的LSTM

x = Bidirectional(LSTM(char_size / 2, return_sequences=True))(x)

@shawroad
Copy link
Owner

是运行到这一行报的错:

编码 两层双向的LSTM

x = Bidirectional(LSTM(char_size / 2, return_sequences=True))(x)

能不能把报错说详细点?  不知道你什么意思

@FankLi
Copy link
Author

FankLi commented Jul 18, 2019

是运行到这一行报的错:

编码 两层双向的LSTM

x = Bidirectional(LSTM(char_size / 2, return_sequences=True))(x)

能不能把报错说详细点?  不知道你什么意思

报错详情如下:
Traceback (most recent call last): File "/Users/xiaoli/PycharmProjects/NLP-Project/021-文章标题的自动生成.py", line 145, in <module> x = Bidirectional(LSTM(char_size / 2, return_sequences=True))(x) File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/keras/layers/wrappers.py", line 427, in __call__ return super(Bidirectional, self).__call__(inputs, **kwargs) File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/keras/engine/base_layer.py", line 431, in __call__ self.build(unpack_singleton(input_shapes)) File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/keras/layers/wrappers.py", line 567, in build self.forward_layer.build(input_shape) File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/keras/layers/recurrent.py", line 493, in build self.cell.build(step_input_shape) File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/keras/layers/recurrent.py", line 1868, in build constraint=self.kernel_constraint) File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 91, in wrapper return func(*args, **kwargs) File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/keras/engine/base_layer.py", line 249, in add_weight weight = K.variable(initializer(shape), File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/keras/initializers.py", line 218, in __call__ dtype=dtype, seed=self.seed) File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 4139, in random_uniform dtype=dtype, seed=seed) File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/tensorflow/python/ops/random_ops.py", line 247, in random_uniform rnd = gen_random_ops.random_uniform(shape, dtype, seed=seed1, seed2=seed2) File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/tensorflow/python/ops/gen_random_ops.py", line 820, in random_uniform name=name) File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 630, in _apply_op_helper param_name=input_name) File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 60, in _SatisfiesTypeConstraint ", ".join(dtypes.as_dtype(x).name for x in allowed_list))) TypeError: Value passed to parameter 'shape' has DataType float32 not in list of allowed values: int32, int64

@shawroad
Copy link
Owner

是运行到这一行报的错:

编码 两层双向的LSTM

x = Bidirectional(LSTM(char_size / 2, return_sequences=True))(x)

能不能把报错说详细点?  不知道你什么意思

报错详情如下:
Traceback (most recent call last): File "/Users/xiaoli/PycharmProjects/NLP-Project/021-文章标题的自动生成.py", line 145, in <module> x = Bidirectional(LSTM(char_size / 2, return_sequences=True))(x) File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/keras/layers/wrappers.py", line 427, in __call__ return super(Bidirectional, self).__call__(inputs, **kwargs) File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/keras/engine/base_layer.py", line 431, in __call__ self.build(unpack_singleton(input_shapes)) File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/keras/layers/wrappers.py", line 567, in build self.forward_layer.build(input_shape) File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/keras/layers/recurrent.py", line 493, in build self.cell.build(step_input_shape) File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/keras/layers/recurrent.py", line 1868, in build constraint=self.kernel_constraint) File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 91, in wrapper return func(*args, **kwargs) File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/keras/engine/base_layer.py", line 249, in add_weight weight = K.variable(initializer(shape), File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/keras/initializers.py", line 218, in __call__ dtype=dtype, seed=self.seed) File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 4139, in random_uniform dtype=dtype, seed=seed) File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/tensorflow/python/ops/random_ops.py", line 247, in random_uniform rnd = gen_random_ops.random_uniform(shape, dtype, seed=seed1, seed2=seed2) File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/tensorflow/python/ops/gen_random_ops.py", line 820, in random_uniform name=name) File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 630, in _apply_op_helper param_name=input_name) File "/anaconda3/envs/NLP-Project/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 60, in _SatisfiesTypeConstraint ", ".join(dtypes.as_dtype(x).name for x in allowed_list))) TypeError: Value passed to parameter 'shape' has DataType float32 not in list of allowed values: int32, int64

这是可能是数据的类型有问题吧。。 你去keras_learning_process这个仓库中去看标题生成的代码。。这个代码应该没问题吧。。 最近很忙,没时间帮你调代码。。

@FankLi
Copy link
Author

FankLi commented Jul 22, 2019

感谢你抽空的回复,keras_learning_process这个跑通了,infer的结果很不理想,如下所示,请问你的结果怎么样呢?

Epoch 100/100
。。。。。。。。
1000/1000 [==============================] - 2213s 2s/step - loss: 0.8461
复活天快天负!还发射不能复出请回射及副业长
1月0日战中,方式8LMML光,报争开脸

@shawroad
Copy link
Owner

shawroad commented Jul 25, 2019 via email

@shawroad
Copy link
Owner

感谢你抽空的回复,keras_learning_process这个跑通了,infer的结果很不理想,如下所示,请问你的结果怎么样呢?

Epoch 100/100
。。。。。。。。
1000/1000 [==============================] - 2213s 2s/step - loss: 0.8461
复活天快天负!还发射不能复出请回射及副业长
1月0日战中,方式8LMML光,报争开脸

其实,这只适合学习。。实际项目中,这样做还是远远不够的。。 建议你在增加数据集。。因为我的数据集太小。。。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants