python - Python Keras TypeError('预期的二进制或 unicode 字符串,得到 %r' % TypeError: 预期的二进制或 unicode 字符串,得到 1
问题描述
通过运行包含更快 rcnn 的 keras 实现的 test.py 脚本,我收到了这个错误:
raise TypeError('Expected binary or unicode string, got %r' %
TypeError: Expected binary or unicode string, got 1
丰富:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File test_frcnn.py", line 125, in <module>
shared_layers = nn.nn_base(img_input, trainable=False)
File resnet.py", line 183, in nn_base
x = FixedBatchNormalization(axis=bn_axis, name='bn_conv1')(x)
raise TypeError("Failed to convert object of type %s to Tensor. "
TypeError: Failed to convert object of type <class 'list'> to Tensor. Contents: [1, None, 1, 1].
Consider casting elements to a supported type.
这是一个非常奇怪的行为,因为它在我的笔记本电脑上返回此错误,而它在 google colab 上完美运行。它是什么?编译器是否有可能返回此错误,因为我已经使用 colab GPU 训练了模型,而现在我正在使用 CPU 在笔记本电脑上编译测试?
完整的追溯:
Traceback (most recent call last):
File test.py", line 125, in <module>
shared_layers = nn.nn_base(img_input, trainable=False)
resnet.py", line 183, in nn_base
x = FixedBatchNormalization(axis=bn_axis, name='bn_conv1')(x)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/keras/backend/tensorflow_backend.py", line 75, in symbolic_fn_wrapper
return func(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/keras/engine/base_layer.py", line 489, in __call__
output = self.call(inputs, **kwargs)
File "/Users/federicolisi/PycharmProjects/neural_networks_GIT/MakeUp_v2/keras-frcnn/keras_frcnn/FixedBatchNormalization.py", line 66, in call
broadcast_running_mean = K.reshape(self.running_mean, broadcast_shape)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/keras/backend/tensorflow_backend.py", line 2440, in reshape
return tf.reshape(x, shape)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py", line 193, in reshape
result = gen_array_ops.reshape(tensor, shape, name)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/ops/gen_array_ops.py", line 8086, in reshape
_, _, _op, _outputs = _op_def_library._apply_op_helper(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/framework/op_def_library.py", line 473, in _apply_op_helper
raise err
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/framework/op_def_library.py", line 465, in _apply_op_helper
values = ops.convert_to_tensor(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/framework/ops.py", line 1341, in convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/framework/constant_op.py", line 321, in _constant_tensor_conversion_function
return constant(v, dtype=dtype, name=name)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/framework/constant_op.py", line 261, in constant
return _constant_impl(value, dtype, shape, name, verify_shape=False,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/framework/constant_op.py", line 298, in _constant_impl
tensor_util.make_tensor_proto(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/framework/tensor_util.py", line 545, in make_tensor_proto
raise TypeError("Failed to convert object of type %s to Tensor. "
TypeError: Failed to convert object of type <class 'list'> to Tensor. Contents: [1, None, 1, 1]. Consider casting elements to a supported type.
解决方案
推荐阅读
- svelte - Svelte:网格布局中翻转动画的外过渡从左上角位置而不是项目位置飞离
- javascript - 如何在所有其他请求之前加载服务人员?
- unity3d - 如何在 Unity3D 中对多个精灵的渲染应用着色器?
- django - CASCADE 究竟是如何与 Django 中的多对多字段一起工作的
- python - 如何在 MPLFinance 图上设置 ylim 和其他图形参数
- cassandra - 在 Cassandra 中过滤主键
- r - 在R中的url中读取数据
- java - period.getDays() 在android中每次返回0
- r - 在大型 RasterStack 上使用 writeRaster 时出错
- nuxt.js - 使用 NuxtJs 将 Body 设置为 100% 高度