我正在尝试使用(?,100,100,1)
将形状为.eval()
的张量转换为numpy数组。但是我一直出错。我认为它无法使用第一维中包含的信息进行转换。我尝试使用clear_session()
,但不起作用。
也许我可以将值1输入该位置。我该怎么办?
我正在自定义层中运行调用方法
def call(self,x):
input_tensor=x
with tf.compat.v1.Session() as sess:
sess.run(tf.compat.v1.global_variables_initializer())
x_unpacked = input_tensor.eval()
.......
我想做的是在定制层中处理每个训练示例有不同的规则,这取决于该训练示例数组中的值。因此,我尝试在每次通话时评估x,这可能不是这样做的结果。
同样,最好在层处理它之前知道如何获取每个训练示例的值,这样我可以在调用语句的其余部分中选择如何处理它。
错误消息如下:
Traceback (most recent call last):
File "/home/usergpu/venv/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1367, in _do_call
return fn(*args)
File "/home/usergpu/venv/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1352, in _run_fn
target_list, run_metadata)
File "/home/usergpu/venv/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1445, in _call_tf_sessionrun
run_metadata)
tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'input_1' with dtype float and shape [?,10 0,100,1]
[[{{node input_1}}]]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "finalvideo_2.py", line 630, in
text()
File "finalvideo_2.py", line 498, in text
kikiE(EX_dat,EY_dat)
File "finalvideo_2.py", line 338, in kikiE
x = MyLayer()(input_tensor)
File "/home/usergpu/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 73, in symbolic_fn_wrapper
return func(*args, **kwargs)
File "/home/usergpu/venv/lib/python3.6/site-packages/keras/engine/base_layer.py", line 489, in call
output = self.call(inputs, **kwargs)
File "finalvideo_2.py", line 108, in call
self.W = topology(x, self.W2)
File "finalvideo_2.py", line 128, in topology
x_unpacked = input_tensor.eval()
File "/home/usergpu/venv/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py", line 790, in eval
return _eval_using_default_session(self, feed_dict, self.graph, session)
File "/home/usergpu/venv/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py", line 5312, in _eval_using_default_session
return session.run(tensors, feed_dict) File "/home/usergpu/venv/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 960, in run
run_metadata_ptr)
File "/home/usergpu/venv/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1183, in _run
feed_dict_tensor, options, run_metadata)
File "/home/usergpu/venv/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1361, in _do_run
run_metadata)
File "/home/usergpu/venv/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1386, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'input_1' with dtype float and shape [?,10 0,100,1]
[[node input_1 (defined at /home/usergpu/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:676) ]]
Original stack trace for 'input_1':
File "finalvideo_2.py", line 630, in
text()
File "finalvideo_2.py", line 498, in text
kikiE(EX_dat,EY_dat)
File "finalvideo_2.py", line 333, in kikiE
input_tensor = Input(shape=X_D[0].shape)
File "/home/usergpu/venv/lib/python3.6/site-packages/keras/engine/input_layer.py", line 178, in Input
input_tensor=tensor)
File "/home/usergpu/venv/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "/home/usergpu/venv/lib/python3.6/site-packages/keras/engine/input_layer.py", line 87, in init
name=self.name)
File "/home/usergpu/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 73, in symbolic_fn_wrapper
return func(*args, **kwargs)
File "/home/usergpu/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 676, in placeholder
shape=shape, ndim=ndim, dtype=dtype, sparse=sparse, name=name)
File "/home/usergpu/venv/lib/python3.6/site-packages/tensorflow_core/python/keras/backend.py", line 1054, in placeholder
x = array_ops.placeholder(dtype, shape=shape, name=name)
File "/home/usergpu/venv/lib/python3.6/site-packages/tensorflow_core/python/ops/array_ops.py", line 2718, in placeholder
return gen_array_ops.placeholder(dtype=dtype, shape=shape, name=name)
File "/home/usergpu/venv/lib/python3.6/site-packages/tensorflow_core/python/ops/gen_array_ops.py", line 6032, in placeholder
"Placeholder", dtype=dtype, shape=shape, name=name)
File "/home/usergpu/venv/lib/python3.6/site-packages/tensorflow_core/python/framework/op_def_library.py", line 742, in _apply_op_helper
attrs=attr_protos, op_def=op_def)
File "/home/usergpu/venv/lib/python3.6/site-packages/tensorflow_core/python/framework/func_graph.py", line 595, in _create_op_internal
compute_device)
File "/home/usergpu/venv/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py", line 3322, in _create_op_internal
op_def=op_def)
File "/home/usergpu/venv/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py", line 1756, in init
self._traceback = tf_stack.extract_stack()