df=pd.DataFrame({
'image_path': 'a',
'valu':[tf.zeros((75,),dtype=tf.dtypes.float32).numpy() ]
})
df=df.iloc[1:, :]
for i in range(10)。
ten=tf.zeros((75,), dtype=tf.dtypes.float32)
ten=ten.numpy()
df.loc[len(df.index)]=['a', ten]
df.head()
df.head()
image_path valu
0 a [0.0, 0.0, 0.0, 0. 0, 0.0, 0.0, 0.0, 0.0, ...
1 a [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, >0.0>。 0, 0.0, 0.0, 0.0, 0.0, ...
2 a [0.0, 0.0, 0.0, 0.0, 0. 0, 0.0, 0.0, 0.0, 0.0, ...
3 a [0.0, 0.0, 0.0, 0.0, 0. 0, 0.0, 0.0, 0.0, 0.0, ...
4 a [0.0, 0.0, 0.0, 0.0, 0. 0, 0.0, 0.0, 0.0, 0.0, ...
y=df.valu
print(y)
y=tf.convert_to_tensor(y)
這個問題發生在開發keras模型時,其中標簽是一個陣列,就像下面給出的鏈接一樣
*這是我得到的錯誤 *
。ValueError Traceback (most recent call last)
<ipython-input-48-108b1fd37149> in < module>
1 y=df.valu
2 print(y)
----> 3 y=tf.convert_to_tensor(y)。
4 print(y.shape)
5 print(y)
/opt/conda/lib/python3.7/site-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
199 ""呼叫目標,并在出現TypeError時退回到調度器。""
200 try。
--> 201 return target(*args, **kwargs)
202 except (TypeError, ValueError)。
203 # Note: convert_to_eager_tensor目前引發一個ValueError,而不是一個。
/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in convert_to_tensor_v2_with_dispatch(value, dtype, dtype_hint, name)
1403 ""
1404 return convert_to_tensor_v2(
-> 1405 value, dtype=dtype, dtype_hint=dtype_hint, name=name)
1406
1407
/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in convert_to_tensor_v2(value, dtype, dtype_hint, name)
1413 name=name。
1414 preferred_dtype=dtype_hint,
-> 1415 as_ref=False)
1416
1417
/opt/conda/lib/python3.7/Site-packages/tensorflow/python/profiler/trace.py in wrapped(*args, **kwargs)
161 with Trace(trace_name, **trace_kwargs):
162 return func(*args, **kwargs)
--> 163 return func(*args, **kwargs)
164
165 回傳包裹的
/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in convert_to_tensor(value, dtype, name, as_ref, preferred_dtype, dtype_hint, ctx, accepted_result_types)
1538
1539 如果ret是無。
-> 1540 ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
1541
1542 if ret is NotImplemented:
/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/constant_op.py in _constant_tensor_conversion_function(v, dtype, name, as_ref)
337 as_ref=False)。)
338 _ = as_ref
--> 339 回傳 constant(v, dtype=dtype, name=name)
340
341
/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/constant_op.py in constant(value, dtype, shape, name)
263 """
264 return _constant_impl(value, dtype, shape, name, verify_shape=False,
--> 265 allow_broadcast=True)
266
267
.7/site-packages/tensorflow/python/framework/constant_op.py in _constant_impl(value, dtype, shape, name, verify_shape, allow_broadcast)
274 with trace.Trace("tf.constant"/span>)。
275 return _constant_eager_impl(ctx, value, dtype, shape, verify_shape)
--> 276 return _constant_eager_impl(ctx, value, dtype, shape, verify_shape)
277
278 g = ops.get_default_graph()
.7/site-packages/tensorflow/python/framework/constant_op.py in _constant_eager_impl(ctx, value, dtype, shape, verify_shape)
299 def _constant_eager_impl(ctx, value, dtype, shape, verify_shape)。
300 ""實作渴望的常量。""
--> 301 t = convert_to_eager_tensor(value, ctx, dtype)
302 if shape is None:
303 return t
.7/site-packages/tensorflow/python/framework/constant_op.py in convert_to_eager_tensor(value, ctx, dtype)
96 dtype = dtypes.as_dtype(type).as_datatype_enum
97 ctx.sure_initialized()
--> 98 return ops.EagerTensor(value, ctx.device_name, dtype)
99
100
ValueError。未能將NumPy陣列轉換為Tensor(不支持的物件 型別 numpy.ndarray)。
這是我得到的錯誤,在上面的輸出中,有一個鏈接,這是原來的問題,但我想出了問題發生的確切位置,因為......需要一個幫助
<uj5u.com熱心網友回復:
x = [list(i) fori in y.values]
y=tf.convert_to_tensor(x)
print(y)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/310708.html
標籤:
