使用数据:https://gist.github.com/TensorTom/d37f4bd605d6a13dfc75015c5e150b82
但这会在训练时期(或恰好在最后一个时期或之后)发生:
---------------------------------------------------------------------------
UnimplementedError Traceback (most recent call last)
/usr/lib/python3.7/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
1333 try:
-> 1334 return fn(*args)
1335 except errors.OpError as e:
/usr/lib/python3.7/site-packages/tensorflow/python/client/session.py in _run_fn(feed_dict, fetch_list, target_list, options, run_metadata)
1318 return self._call_tf_sessionrun(
-> 1319 options, feed_dict, fetch_list, target_list, run_metadata)
1320
/usr/lib/python3.7/site-packages/tensorflow/python/client/session.py in _call_tf_sessionrun(self, options, feed_dict, fetch_list, target_list, run_metadata)
1406 self._session, options, feed_dict, fetch_list, target_list,
-> 1407 run_metadata)
1408
UnimplementedError: TensorArray has size zero, but element shape [?,128] is not fully defined. Currently only static shapes are supported when packing zero-size TensorArrays.
[[{{node decoder/bidirectional_rnn/fw/fw/TensorArrayStack/TensorArrayGatherV3}}]]
[[{{node decoder/bidirectional_rnn/bw/bw/while/Exit_3}}]]
During handling of the above exception, another exception occurred:
UnimplementedError Traceback (most recent call last)
<ipython-input-8-07a23d0b1dbd> in <module>
22 modelnn.X: np.expand_dims(df_log.iloc[upper_b:], axis = 0),
23 modelnn.backward_hidden_layer: init_value_backward,
---> 24 modelnn.forward_hidden_layer: init_value_forward,
25 },
26 )
/usr/lib/python3.7/site-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
927 try:
928 result = self._run(None, fetches, feed_dict, options_ptr,
--> 929 run_metadata_ptr)
930 if run_metadata:
931 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
/usr/lib/python3.7/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
1150 if final_fetches or final_targets or (handle and feed_dict_tensor):
1151 results = self._do_run(handle, final_targets, final_fetches,
-> 1152 feed_dict_tensor, options, run_metadata)
1153 else:
1154 results = []
/usr/lib/python3.7/site-packages/tensorflow/python/client/session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
1326 if handle is None:
1327 return self._do_call(_run_fn, feeds, fetches, targets, options,
-> 1328 run_metadata)
1329 else:
1330 return self._do_call(_prun_fn, handle, feeds, fetches)
/usr/lib/python3.7/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
1346 pass
1347 message = error_interpolation.interpolate(message, self._graph)
-> 1348 raise type(e)(node_def, op, message)
1349
1350 def _extend_graph(self):
UnimplementedError: TensorArray has size zero, but element shape [?,128] is not fully defined. Currently only static shapes are supported when packing zero-size TensorArrays.
[[node decoder/bidirectional_rnn/fw/fw/TensorArrayStack/TensorArrayGatherV3 (defined at <ipython-input-5-7fc0ccd4ec49>:97) ]]
[[node decoder/bidirectional_rnn/bw/bw/while/Exit_3 (defined at <ipython-input-5-7fc0ccd4ec49>:97) ]]
Caused by op 'decoder/bidirectional_rnn/fw/fw/TensorArrayStack/TensorArrayGatherV3', defined at:
File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/lib/python3.7/site-packages/ipykernel_launcher.py", line 16, in <module>
app.launch_new_instance()
File "/usr/lib/python3.7/site-packages/traitlets/config/application.py", line 658, in launch_instance
app.start()
File "/usr/lib/python3.7/site-packages/ipykernel/kernelapp.py", line 505, in start
self.io_loop.start()
File "/usr/lib/python3.7/site-packages/tornado/platform/asyncio.py", line 132, in start
self.asyncio_loop.run_forever()
File "/usr/lib/python3.7/asyncio/base_events.py", line 539, in run_forever
self._run_once()
File "/usr/lib/python3.7/asyncio/base_events.py", line 1775, in _run_once
handle._run()
File "/usr/lib/python3.7/asyncio/events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File "/usr/lib/python3.7/site-packages/tornado/ioloop.py", line 758, in _run_callback
ret = callback()
File "/usr/lib/python3.7/site-packages/tornado/stack_context.py", line 300, in null_wrapper
return fn(*args, **kwargs)
File "/usr/lib/python3.7/site-packages/tornado/gen.py", line 1233, in inner
self.run()
File "/usr/lib/python3.7/site-packages/tornado/gen.py", line 1147, in run
yielded = self.gen.send(value)
File "/usr/lib/python3.7/site-packages/ipykernel/kernelbase.py", line 370, in dispatch_queue
yield self.process_one()
File "/usr/lib/python3.7/site-packages/tornado/gen.py", line 346, in wrapper
runner = Runner(result, future, yielded)
File "/usr/lib/python3.7/site-packages/tornado/gen.py", line 1080, in __init__
self.run()
File "/usr/lib/python3.7/site-packages/tornado/gen.py", line 1147, in run
yielded = self.gen.send(value)
File "/usr/lib/python3.7/site-packages/ipykernel/kernelbase.py", line 357, in process_one
yield gen.maybe_future(dispatch(*args))
File "/usr/lib/python3.7/site-packages/tornado/gen.py", line 326, in wrapper
yielded = next(result)
File "/usr/lib/python3.7/site-packages/ipykernel/kernelbase.py", line 267, in dispatch_shell
yield gen.maybe_future(handler(stream, idents, msg))
File "/usr/lib/python3.7/site-packages/tornado/gen.py", line 326, in wrapper
yielded = next(result)
File "/usr/lib/python3.7/site-packages/ipykernel/kernelbase.py", line 534, in execute_request
user_expressions, allow_stdin,
File "/usr/lib/python3.7/site-packages/tornado/gen.py", line 326, in wrapper
yielded = next(result)
File "/usr/lib/python3.7/site-packages/ipykernel/ipkernel.py", line 294, in do_execute
res = shell.run_cell(code, store_history=store_history, silent=silent)
File "/usr/lib/python3.7/site-packages/ipykernel/zmqshell.py", line 536, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File "/usr/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 2819, in run_cell
raw_cell, store_history, silent, shell_futures)
File "/usr/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 2845, in _run_cell
return runner(coro)
File "/usr/lib/python3.7/site-packages/IPython/core/async_helpers.py", line 67, in _pseudo_sync_runner
coro.send(None)
File "/usr/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3020, in run_cell_async
interactivity=interactivity, compiler=compiler, result=result)
File "/usr/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3185, in run_ast_nodes
if (yield from self.run_code(code, result)):
File "/usr/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3267, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-6-2e75d5202b26>", line 2, in <module>
modelnn = Model(0.01, num_layers, df_log.shape[1], size_layer, df_log.shape[1], dropout_rate)
File "<ipython-input-5-7fc0ccd4ec49>", line 97, in __init__
dtype = tf.float32,
File "/usr/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py", line 324, in new_func
return func(*args, **kwargs)
File "/usr/lib/python3.7/site-packages/tensorflow/python/ops/rnn.py", line 443, in bidirectional_dynamic_rnn
time_major=time_major, scope=fw_scope)
File "/usr/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py", line 324, in new_func
return func(*args, **kwargs)
File "/usr/lib/python3.7/site-packages/tensorflow/python/ops/rnn.py", line 671, in dynamic_rnn
dtype=dtype)
File "/usr/lib/python3.7/site-packages/tensorflow/python/ops/rnn.py", line 883, in _dynamic_rnn_loop
final_outputs = tuple(ta.stack() for ta in output_final_ta)
File "/usr/lib/python3.7/site-packages/tensorflow/python/ops/rnn.py", line 883, in <genexpr>
final_outputs = tuple(ta.stack() for ta in output_final_ta)
File "/usr/lib/python3.7/site-packages/tensorflow/python/ops/tensor_array_ops.py", line 1128, in stack
return self._implementation.stack(name=name)
File "/usr/lib/python3.7/site-packages/tensorflow/python/ops/tensor_array_ops.py", line 292, in stack
return self.gather(math_ops.range(0, self.size()), name=name)
File "/usr/lib/python3.7/site-packages/tensorflow/python/ops/tensor_array_ops.py", line 306, in gather
element_shape=element_shape)
File "/usr/lib/python3.7/site-packages/tensorflow/python/ops/gen_data_flow_ops.py", line 6291, in tensor_array_gather_v3
element_shape=element_shape, name=name)
File "/usr/lib/python3.7/site-packages/tensorflow/python/framework/op_def_library.py", line 788, in _apply_op_helper
op_def=op_def)
File "/usr/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "/usr/lib/python3.7/site-packages/tensorflow/python/framework/ops.py", line 3300, in create_op
op_def=op_def)
File "/usr/lib/python3.7/site-packages/tensorflow/python/framework/ops.py", line 1801, in __init__
self._traceback = tf_stack.extract_stack()
UnimplementedError (see above for traceback): TensorArray has size zero, but element shape [?,128] is not fully defined. Currently only static shapes are supported when packing zero-size TensorArrays.
[[node decoder/bidirectional_rnn/fw/fw/TensorArrayStack/TensorArrayGatherV3 (defined at <ipython-input-5-7fc0ccd4ec49>:97) ]]
[[node decoder/bidirectional_rnn/bw/bw/while/Exit_3 (defined at <ipython-input-5-7fc0ccd4ec49>:97) ]]
因此,我与使用相同脚本的某人进行了交谈,他们建议这是因为我的数据集太多了;他们能够通过将数据行限制为400行来避免此错误。确实确实消除了错误,但是并不能解决问题。
对于每行OHLCV数据1天,使用<400行是可以的,但是如果我想使用较短的时间范围,例如每行OHLCV数据为1分钟,那么400行将不会被削减。
如何使该模型接受任意数据行?