I have problem in problem in the anaconda environment. Every time I try this test, I get errors between internal libraries. Does anyone know which library versions to use? Here’s the code:
# test-IA
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow import keras
import pandas as pd
from keras.models import Sequential
from keras.layers import LSTM, Dense, SimpleRNN
from keras.utils import to_categorical
from keras.optimizers import Adam
import sklearn
from sklearn.preprocessing import MinMaxScaler
print("version de python : ", sys.version)
print("version TensorFlow : ", tf.__version__)
print("version Panda : ", pd.__version__)
print("version Keras : ", tf.keras.__version__)
print("Num GPUs Available: ", len(tf.config.list_physical_devices('GPU')))
print("version sklearn : ", sklearn.__version__)
# Utilise-t'on un TF compilé pour GPU ?
print("built with cuda ?", tf.test.is_built_with_cuda())
# TF voit-il la carte nvidia ?
print("Appareils GPU visibles:", tf.config.list_physical_devices('GPU'))
# Création du modèle LSTM
model = Sequential()
model.add(LSTM(50, return_sequences=True, input_shape=(36, 1)))
model.add(LSTM(50, return_sequences=False))
model.add(Dense(25))
model.add(Dense(4, activation='softmax'))
and here’s the result:
[GCC 11.2.0]
version TensorFlow : 2.4.1
version Panda : 2.2.2
version Keras : 2.4.0
Num GPUs Available: 1
version sklearn : 1.1.3
built with cuda ? True
Appareils GPU visibles: [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
File ~/anaconda3/envs/IA-01/lib/python3.9/site-packages/tensorflow/python/keras/engine/base_layer.py:822, in Layer._keras_tensor_symbolic_call(self, inputs, input_masks, args, kwargs)
820 return nest.map_structure(keras_tensor.KerasTensor, output_signature)
821 else:
--> 822 return self._infer_output_signature(inputs, args, kwargs, input_masks)
File ~/anaconda3/envs/IA-01/lib/python3.9/site-packages/tensorflow/python/keras/engine/base_layer.py:863, in Layer._infer_output_signature(self, inputs, args, kwargs, input_masks)
857 with autocast_variable.enable_auto_cast_variables(
858 self._compute_dtype_object):
859 # Build layer if applicable (if the `build` method has been
860 # overridden).
861 # TODO(kaftan): do we maybe_build here, or have we already done it?
862 self._maybe_build(inputs)
--> 863 outputs = call_fn(inputs, *args, **kwargs)
865 self._handle_activity_regularization(inputs, outputs)
866 self._set_mask_metadata(inputs, outputs, input_masks,
867 build_graph=False)
File ~/anaconda3/envs/IA-01/lib/python3.9/site-packages/tensorflow/python/keras/layers/recurrent_v2.py:1157, in LSTM.call(self, inputs, mask, training, initial_state)
1154 self._validate_args_if_ragged(is_ragged_input, mask)
1156 # LSTM does not support constants. Ignore it during process.
-> 1157 inputs, initial_state, _ = self._process_inputs(inputs, initial_state, None)
1159 if isinstance(mask, list):
1160 mask = mask[0]
File ~/anaconda3/envs/IA-01/lib/python3.9/site-packages/tensorflow/python/keras/layers/recurrent.py:859, in RNN._process_inputs(self, inputs, initial_state, constants)
857 initial_state = self.states
858 elif initial_state is None:
--> 859 initial_state = self.get_initial_state(inputs)
861 if len(initial_state) != len(self.states):
862 raise ValueError('Layer has ' + str(len(self.states)) +
863 ' states but was passed ' + str(len(initial_state)) +
864 ' initial states.')
File ~/anaconda3/envs/IA-01/lib/python3.9/site-packages/tensorflow/python/keras/layers/recurrent.py:642, in RNN.get_initial_state(self, inputs)
640 dtype = inputs.dtype
641 if get_initial_state_fn:
--> 642 init_state = get_initial_state_fn(
643 inputs=None, batch_size=batch_size, dtype=dtype)
644 else:
645 init_state = _generate_zero_filled_state(batch_size, self.cell.state_size,
646 dtype)
File ~/anaconda3/envs/IA-01/lib/python3.9/site-packages/tensorflow/python/keras/layers/recurrent.py:2506, in LSTMCell.get_initial_state(self, inputs, batch_size, dtype)
2505 def get_initial_state(self, inputs=None, batch_size=None, dtype=None):
-> 2506 return list(_generate_zero_filled_state_for_cell(
2507 self, inputs, batch_size, dtype))
File ~/anaconda3/envs/IA-01/lib/python3.9/site-packages/tensorflow/python/keras/layers/recurrent.py:2987, in _generate_zero_filled_state_for_cell(cell, inputs, batch_size, dtype)
2985 batch_size = array_ops.shape(inputs)[0]
2986 dtype = inputs.dtype
-> 2987 return _generate_zero_filled_state(batch_size, cell.state_size, dtype)
File ~/anaconda3/envs/IA-01/lib/python3.9/site-packages/tensorflow/python/keras/layers/recurrent.py:3003, in _generate_zero_filled_state(batch_size_tensor, state_size, dtype)
3000 return array_ops.zeros(init_state_size, dtype=dtype)
3002 if nest.is_nested(state_size):
-> 3003 return nest.map_structure(create_zeros, state_size)
3004 else:
3005 return create_zeros(state_size)
File ~/anaconda3/envs/IA-01/lib/python3.9/site-packages/tensorflow/python/util/nest.py:659, in map_structure(func, *structure, **kwargs)
655 flat_structure = (flatten(s, expand_composites) for s in structure)
656 entries = zip(*flat_structure)
658 return pack_sequence_as(
--> 659 structure[0], [func(*x) for x in entries],
660 expand_composites=expand_composites)
File ~/anaconda3/envs/IA-01/lib/python3.9/site-packages/tensorflow/python/util/nest.py:659, in <listcomp>(.0)
655 flat_structure = (flatten(s, expand_composites) for s in structure)
656 entries = zip(*flat_structure)
658 return pack_sequence_as(
--> 659 structure[0], [func(*x) for x in entries],
660 expand_composites=expand_composites)
File ~/anaconda3/envs/IA-01/lib/python3.9/site-packages/tensorflow/python/keras/layers/recurrent.py:3000, in _generate_zero_filled_state.<locals>.create_zeros(unnested_state_size)
2998 flat_dims = tensor_shape.TensorShape(unnested_state_size).as_list()
2999 init_state_size = [batch_size_tensor] + flat_dims
-> 3000 return array_ops.zeros(init_state_size, dtype=dtype)
File ~/anaconda3/envs/IA-01/lib/python3.9/site-packages/tensorflow/python/util/dispatch.py:201, in add_dispatch_support.<locals>.wrapper(*args, **kwargs)
199 """Call target, and fall back on dispatchers if there is a TypeError."""
200 try:
--> 201 return target(*args, **kwargs)
202 except (TypeError, ValueError):
203 # Note: convert_to_eager_tensor currently raises a ValueError, not a
204 # TypeError, when given unexpected types. So we need to catch both.
205 result = dispatch(wrapper, args, kwargs)
File ~/anaconda3/envs/IA-01/lib/python3.9/site-packages/tensorflow/python/ops/array_ops.py:2819, in _tag_zeros_tensor.<locals>.wrapped(*args, **kwargs)
2818 def wrapped(*args, **kwargs):
-> 2819 tensor = fun(*args, **kwargs)
2820 tensor._is_zeros_tensor = True
2821 return tensor
File ~/anaconda3/envs/IA-01/lib/python3.9/site-packages/tensorflow/python/ops/array_ops.py:2868, in zeros(shape, dtype, name)
2864 try:
2865 if not context.executing_eagerly():
2866 # Create a constant if it won't be very big. Otherwise create a fill
2867 # op to prevent serialized GraphDefs from becoming too large.
-> 2868 output = _constant_if_small(zero, shape, dtype, name)
2869 if output is not None:
2870 return output
File ~/anaconda3/envs/IA-01/lib/python3.9/site-packages/tensorflow/python/ops/array_ops.py:2804, in _constant_if_small(value, shape, dtype, name)
2802 def _constant_if_small(value, shape, dtype, name):
2803 try:
-> 2804 if np.prod(shape) < 1000:
2805 return constant(value, shape=shape, dtype=dtype, name=name)
2806 except TypeError:
2807 # Happens when shape is a Tensor, list with Tensor elements, etc.
File <__array_function__ internals>:180, in prod(*args, **kwargs)
File ~/anaconda3/envs/IA-01/lib/python3.9/site-packages/numpy/core/fromnumeric.py:3045, in prod(a, axis, dtype, out, keepdims, initial, where)
2927 @array_function_dispatch(_prod_dispatcher)
2928 def prod(a, axis=None, dtype=None, out=None, keepdims=np._NoValue,
2929 initial=np._NoValue, where=np._NoValue):
2930 """
2931 Return the product of array elements over a given axis.
2932
(...)
3043 10
3044 """
-> 3045 return _wrapreduction(a, np.multiply, 'prod', axis, dtype, out,
3046 keepdims=keepdims, initial=initial, where=where)
File ~/anaconda3/envs/IA-01/lib/python3.9/site-packages/numpy/core/fromnumeric.py:86, in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs)
83 else:
84 return reduction(axis=axis, out=out, **passkwargs)
---> 86 return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
File ~/anaconda3/envs/IA-01/lib/python3.9/site-packages/tensorflow/python/framework/ops.py:852, in Tensor.__array__(self)
851 def __array__(self):
--> 852 raise NotImplementedError(
853 "Cannot convert a symbolic Tensor ({}) to a numpy array."
854 " This error may indicate that you're trying to pass a Tensor to"
855 " a NumPy call, which is not supported".format(self.name))
NotImplementedError: Cannot convert a symbolic Tensor (lstm_3/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
?? HELP !
Thanks