Categories
Misc

Numpy-related error when building model

I am using tensorflow 2.4.1 with numpy 1.20.0, and I am trying to create a model using LSTM.

model = Sequential() model.add(LSTM(256, input_shape=(1, 66), return_sequences=True )) 

Adding that LSTM layer gives me this error:

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/sakuya/.local/lib/python3.8/site-packages/tensorflow/python/training/tracking/base.py", line 517, in _method_wrapper result = method(self, *args, **kwargs) File "/home/sakuya/.local/lib/python3.8/site-packages/tensorflow/python/keras/engine/sequential.py", line 208, in add layer(x) File "/home/sakuya/.local/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent.py", line 660, in __call__ return super(RNN, self).__call__(inputs, **kwargs) File "/home/sakuya/.local/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py", line 951, in __call__ return self._functional_construction_call(inputs, args, kwargs, File "/home/sakuya/.local/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py", line 1090, in _functional_construction_call outputs = self._keras_tensor_symbolic_call( File "/home/sakuya/.local/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py", line 822, in _keras_tensor_symbolic_call return self._infer_output_signature(inputs, args, kwargs, input_masks) File "/home/sakuya/.local/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py", line 863, in _infer_output_signature outputs = call_fn(inputs, *args, **kwargs) File "/home/sakuya/.local/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent_v2.py", line 1157, in call inputs, initial_state, _ = self._process_inputs(inputs, initial_state, None) File "/home/sakuya/.local/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent.py", line 859, in _process_inputs initial_state = self.get_initial_state(inputs) File "/home/sakuya/.local/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent.py", line 642, in get_initial_state init_state = get_initial_state_fn( File "/home/sakuya/.local/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent.py", line 2506, in get_initial_state return list(_generate_zero_filled_state_for_cell( File "/home/sakuya/.local/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent.py", line 2987, in _generate_zero_filled_state_for_cell return _generate_zero_filled_state(batch_size, cell.state_size, dtype) File "/home/sakuya/.local/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent.py", line 3003, in _generate_zero_filled_state return nest.map_structure(create_zeros, state_size) File "/home/sakuya/.local/lib/python3.8/site-packages/tensorflow/python/util/nest.py", line 659, in map_structure structure[0], [func(*x) for x in entries], File "/home/sakuya/.local/lib/python3.8/site-packages/tensorflow/python/util/nest.py", line 659, in <listcomp> structure[0], [func(*x) for x in entries], File "/home/sakuya/.local/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent.py", line 3000, in create_zeros return array_ops.zeros(init_state_size, dtype=dtype) File "/home/sakuya/.local/lib/python3.8/site-packages/tensorflow/python/util/dispatch.py", line 201, in wrapper return target(*args, **kwargs) File "/home/sakuya/.local/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py", line 2819, in wrapped tensor = fun(*args, **kwargs) File "/home/sakuya/.local/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py", line 2868, in zeros output = _constant_if_small(zero, shape, dtype, name) File "/home/sakuya/.local/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py", line 2804, in _constant_if_small if np.prod(shape) < 1000: File "<__array_function__ internals>", line 5, in prod File "/home/sakuya/.local/lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 3030, in prod return _wrapreduction(a, np.multiply, 'prod', axis, dtype, out, File "/home/sakuya/.local/lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 87, in _wrapreduction return ufunc.reduce(obj, axis, dtype, out, **passkwargs) File "/home/sakuya/.local/lib/python3.8/site-packages/tensorflow/python/framework/ops.py", line 852, in __array__ raise NotImplementedError( NotImplementedError: Cannot convert a symbolic Tensor (lstm_19/strided_slice:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported 

I have no idea where I am going wrong here, but I can add the layer if I do not specify the input shape, but I need to do that.

submitted by /u/lastorder
[visit reddit] [comments]

Leave a Reply

Your email address will not be published. Required fields are marked *