ValueError Traceback (most recent call last)
in ()
5 data = np.array([[0.1, 0.2, 0.3], [0.8, 0.9, 1.0], [1.5, 1.6, 1.7],])
6 layer = preprocessing.Normalization()
----> 7 layer.adapt(data)
8 normalized_data = layer(data)
~\.conda\envs\py35\lib\site-packages\tensorflow\python\keras\engine\base_preprocessing_layer.py in adapt(self, data, reset_state)
214
215 updates = self._combiner.extract(accumulator)
--> 216 self._set_state_variables(updates)
217
218 def _set_state_variables(self, updates):
~\.conda\envs\py35\lib\site-packages\tensorflow\python\keras\engine\base_preprocessing_layer.py in _set_state_variables(self, updates)
235 with ops.init_scope():
236 for var_name, value in updates.items():
--> 237 self.state_variables[var_name].assign(value)
238
239
~\.conda\envs\py35\lib\site-packages\tensorflow\python\ops\resource_variable_ops.py in assign(self, value, use_locking, name, read_value)
855 # initialize the variable.
856 with _handle_graph(self.handle):
--> 857 value_tensor = ops.convert_to_tensor(value, dtype=self.dtype)
858 self._shape.assert_is_compatible_with(value_tensor.shape)
859 assign_op = gen_resource_variable_ops.assign_variable_op(
~\.conda\envs\py35\lib\site-packages\tensorflow\python\framework\ops.py in convert_to_tensor(value, dtype, name, as_ref, preferred_dtype, dtype_hint, ctx, accepted_result_types)
1497
1498 if ret is None:
-> 1499 ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
1500
1501 if ret is NotImplemented:
~\.conda\envs\py35\lib\site-packages\tensorflow\python\framework\tensor_conversion_registry.py in _default_conversion_function(***failed resolving arguments***)
50 def _default_conversion_function(value, dtype, name, as_ref):
51 del as_ref # Unused.
---> 52 return constant_op.constant(value, dtype, name=name)
53
54
~\.conda\envs\py35\lib\site-packages\tensorflow\python\framework\constant_op.py in constant(value, dtype, shape, name)
262 """
263 return _constant_impl(value, dtype, shape, name, verify_shape=False,
--> 264 allow_broadcast=True)
265
266
~\.conda\envs\py35\lib\site-packages\tensorflow\python\framework\constant_op.py in _constant_impl(value, dtype, shape, name, verify_shape, allow_broadcast)
273 with trace.Trace("tf.constant"):
274 return _constant_eager_impl(ctx, value, dtype, shape, verify_shape)
--> 275 return _constant_eager_impl(ctx, value, dtype, shape, verify_shape)
276
277 g = ops.get_default_graph()
~\.conda\envs\py35\lib\site-packages\tensorflow\python\framework\constant_op.py in _constant_eager_impl(ctx, value, dtype, shape, verify_shape)
298 def _constant_eager_impl(ctx, value, dtype, shape, verify_shape):
299 """Implementation of eager constant."""
--> 300 t = convert_to_eager_tensor(value, ctx, dtype)
301 if shape is None:
302 return t
~\.conda\envs\py35\lib\site-packages\tensorflow\python\framework\constant_op.py in convert_to_eager_tensor(value, ctx, dtype)
96 dtype = dtypes.as_dtype(dtype).as_datatype_enum
97 ctx.ensure_initialized()
---> 98 return ops.EagerTensor(value, ctx.device_name, dtype)
99
100
ValueError: object __array__ method not producing an array
Я провел небольшое исследование, но не смог найти ответа на свою проблему.
Что я делаю не так? Я использую Tensorflow версии 2.3.0, Numpy 1.14.2, Python 3.5 на Win10.
Спасибо за помощь, ребята!
Я относительно новичок в машинном обучении и пытаюсь нормализовать некоторые данные. Вот фрагмент кода. [code]import numpy as np import tensorflow as tf from tensorflow.keras.layers.experimental import preprocessing
data = np.array([[0.1, 0.2, 0.3], [0.8, 0.9, 1.0], [1.5, 1.6, 1.7],]) layer = preprocessing.Normalization() layer.adapt(data) normalized_data = layer(data) [/code] Однако, когда я запускаю код, Python сообщает мне, что метод массива объектов не создает массив. [code]ValueError Traceback (most recent call last) in () 5 data = np.array([[0.1, 0.2, 0.3], [0.8, 0.9, 1.0], [1.5, 1.6, 1.7],]) 6 layer = preprocessing.Normalization() ----> 7 layer.adapt(data) 8 normalized_data = layer(data)
~\.conda\envs\py35\lib\site-packages\tensorflow\python\keras\engine\base_preprocessing_layer.py in _set_state_variables(self, updates) 235 with ops.init_scope(): 236 for var_name, value in updates.items(): --> 237 self.state_variables[var_name].assign(value) 238 239
~\.conda\envs\py35\lib\site-packages\tensorflow\python\ops\resource_variable_ops.py in assign(self, value, use_locking, name, read_value) 855 # initialize the variable. 856 with _handle_graph(self.handle): --> 857 value_tensor = ops.convert_to_tensor(value, dtype=self.dtype) 858 self._shape.assert_is_compatible_with(value_tensor.shape) 859 assign_op = gen_resource_variable_ops.assign_variable_op(
~\.conda\envs\py35\lib\site-packages\tensorflow\python\framework\ops.py in convert_to_tensor(value, dtype, name, as_ref, preferred_dtype, dtype_hint, ctx, accepted_result_types) 1497 1498 if ret is None: -> 1499 ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) 1500 1501 if ret is NotImplemented:
ValueError: object __array__ method not producing an array [/code] Я провел небольшое исследование, но не смог найти ответа на свою проблему. Что я делаю не так? Я использую Tensorflow версии 2.3.0, Numpy 1.14.2, Python 3.5 на Win10. Спасибо за помощь, ребята!