yacoubb / stock-trading-ml

A stock trading bot that uses machine learning to make price predictions.
GNU General Public License v3.0
598 stars 254 forks source link

ValueError #24

Open linuxdebian opened 3 years ago

linuxdebian commented 3 years ago

I am getting the following error when I run "python trading_algo.py"

2021-02-13 10:43:34.165315: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1 2021-02-13 10:43:36.611898: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set 2021-02-13 10:43:36.613079: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcuda.so.1 2021-02-13 10:43:36.635749: E tensorflow/stream_executor/cuda/cuda_driver.cc:328] failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected 2021-02-13 10:43:36.635814: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (821e3f25af0b): /proc/driver/nvidia/version does not exist 2021-02-13 10:43:36.636356: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set 2021-02-13 10:43:37.423855: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:116] None of the MLIR optimization passes are enabled (registered 2) 2021-02-13 10:43:37.424339: I tensorflow/core/platform/profile_utils/cpu_utils.cc:112] CPU Frequency: 2299995000 Hz Traceback (most recent call last): File "trading_algo.py", line 37, in predicted_price_tomorrow = np.squeeze(y_normaliser.inverse_transform(model.predict([[ohlcv], [ind]]))) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py", line 1608, in predict steps_per_execution=self._steps_per_execution) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/data_adapter.py", line 1112, in init model=model) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/data_adapter.py", line 274, in init _check_data_cardinality(inputs) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/data_adapter.py", line 1529, in _check_data_cardinality raise ValueError(msg) ValueError: Data cardinality is ambiguous: x sizes: 50, 1 Make sure all arrays contain the same number of samples.

LeagueLugas commented 3 years ago

I get an error like this too. What should I do?

dkubanyi commented 3 years ago

@linuxdebian @LeagueLugas this is already resolved in https://github.com/yacoubb/stock-trading-ml/issues/18#issuecomment-675791707:

i found the problem and the fix: In predicted_price_tomorrow = np.squeeze(y_normaliser.inverse_transform(model.predict([[ohlcv], [ind]]))), model.predict() is expecting (in this case) a list of arrays. Instead, we are currently passing in a list of lists. To fix this, all you need to do is change model.predict([[ohlcv], [ind]]) to model.predict([np.array([ohlcv]), np.array([ind])])

RuanSerfontein commented 3 years ago

I am getting a similar issue and I think it may be related to this.

I am getting the following error: 2021-06-25 15:23:09.091068: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library cudart64_110.dll 2021-06-25 15:23:12.078912: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library nvcuda.dll 2021-06-25 15:23:12.112451: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1733] Found device 0 with properties: pciBusID: 0000:01:00.0 name: GeForce GTX 1660 Ti with Max-Q Design computeCapability: 7.5 coreClock: 1.335GHz coreCount: 24 deviceMemorySize: 6.00GiB deviceMemoryBandwidth: 268.26GiB/s 2021-06-25 15:23:12.112576: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library cudart64_110.dll 2021-06-25 15:23:12.121459: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library cublas64_11.dll 2021-06-25 15:23:12.121605: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library cublasLt64_11.dll 2021-06-25 15:23:12.125891: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library cufft64_10.dll 2021-06-25 15:23:12.127195: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library curand64_10.dll 2021-06-25 15:23:12.137114: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library cusolver64_11.dll 2021-06-25 15:23:12.140947: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library cusparse64_11.dll 2021-06-25 15:23:12.142136: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudnn64_8.dll'; dlerror: cudnn64_8.dll not found 2021-06-25 15:23:12.142194: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1766] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform. Skipping registering GPU devices... 2021-06-25 15:23:12.142952: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2 To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. 2021-06-25 15:23:12.143771: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1258] Device interconnect StreamExecutor with strength 1 edge matrix: 2021-06-25 15:23:12.143852: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1264] 2021-06-25 15:23:12.915007: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:176] None of the MLIR Optimization Passes are enabled (registered 2) Traceback (most recent call last): File "trading_algo.py", line 22, in y_test_predicted = model.predict([ohlcv_test, tech_ind_test]) File "C:\Users\Ruans\AppData\Local\Programs\Python\Python38\lib\site-packages\keras\engine\training.py", line 1702, in predict tmp_batch_outputs = self.predict_function(iterator) File "C:\Users\Ruans\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\eager\def_function.py", line 889, in call result = self._call(*args, kwds) File "C:\Users\Ruans\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\eager\def_function.py", line 933, in _call self._initialize(args, kwds, add_initializers_to=initializers) File "C:\Users\Ruans\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\eager\def_function.py", line 763, in _initialize self._stateful_fn._get_concrete_function_internal_garbage_collected( # pylint: disable=protected-access File "C:\Users\Ruans\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\eager\function.py", line 3050, in _get_concrete_function_internal_garbage_collected graphfunction, = self._maybe_define_function(args, kwargs) File "C:\Users\Ruans\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\eager\function.py", line 3444, in _maybe_define_function graph_function = self._create_graph_function(args, kwargs) File "C:\Users\Ruans\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\eager\function.py", line 3279, in _create_graph_function func_graph_module.func_graph_from_py_func( File "C:\Users\Ruans\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\framework\func_graph.py", line 999, in func_graph_from_py_func func_outputs = python_func(*func_args, *func_kwargs) File "C:\Users\Ruans\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\eager\def_function.py", line 672, in wrapped_fn out = weak_wrapped_fn().wrapped(args, kwds) File "C:\Users\Ruans\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\framework\func_graph.py", line 986, in wrapper raise e.ag_error_metadata.to_exception(e) ValueError: in user code:

C:\Users\Ruans\AppData\Local\Programs\Python\Python38\lib\site-packages\keras\engine\training.py:1544 predict_function  *
    return step_function(self, iterator)
C:\Users\Ruans\AppData\Local\Programs\Python\Python38\lib\site-packages\keras\engine\training.py:1527 run_step  *
    outputs = model.predict_step(data)
C:\Users\Ruans\AppData\Local\Programs\Python\Python38\lib\site-packages\keras\engine\training.py:1500 predict_step  *
    return self(x, training=False)
C:\Users\Ruans\AppData\Local\Programs\Python\Python38\lib\site-packages\keras\engine\base_layer.py:989 __call__  *
    input_spec.assert_input_compatibility(self.input_spec, inputs, self.name)
C:\Users\Ruans\AppData\Local\Programs\Python\Python38\lib\site-packages\keras\engine\input_spec.py:197 assert_input_compatibility  *
    raise ValueError('Layer ' + layer_name + ' expects ' +

ValueError: Layer model expects 1 input(s), but it received 2 input tensors. Inputs received: [<tf.Tensor 'IteratorGetNext:0' shape=(None, 50, 5) dtype=float32>, <tf.Tensor 'IteratorGetNext:1' shape=(None, 1) dtype=float32>]

I have tried updating "y_test_predicted = model.predict([ohlcv_test, tech_ind_test])" to y_test_predicted = model.predict([np.array(ohlcv_test), np.array(tech_ind_test)])

npavgi commented 2 years ago

@RuanSerfontein - what model.h5 are you using within the trading_algo.py file? I was using basic_model.h5 and it produced the "Layer model expects 1 input(s), but it received 2 input tensors" error. The reason is that trading_algo.py requires the technical indicator as well and that is only provided by the technical_model.h5. Hope this helps.