将数据帧转换为张量二进制或字符串错误

时间:2018-08-15 16:55:20

标签: python-3.x tensorflow numpy-ndarray

我在下面的代码中尝试将pandas数据帧转换为具有tensorflow的张量。我首先使用“ .values”将其转换为一个numpy数组,然后尝试使用convert_to_tensor将其转换为张量,但是下面出现了错误。谁能告诉我我在做什么错以及如何解决?

数据:

print(test_result)

            channel_0 channel_1 channel_2 channel_3  channel_4
2014-01-05  0.0255506    0.1006  0.111489  0.351855  0.0875379
2014-01-12   0.280675  0.291868  0.129358  0.333653   0.356215
2014-01-19   0.324742  0.240964  0.114397  0.189708   0.515657

test_result.values

array([[0.025550554, 0.10060038, 0.111488804, 0.3518546, 0.08753788],
       [0.280675, 0.29186815, 0.12935837, 0.33365345, 0.35621548],
       [0.32474187, 0.24096353, 0.11439703, 0.18970811, 0.5156571]],
      dtype=object)

代码:

test_convert=tf.convert_to_tensor(test_result.values)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-134-065d7d40920a> in <module>()
----> 1 test_convert=tf.convert_to_tensor(test_result.values)

~/anaconda2/envs/py36/lib/python3.6/site-packages/tensorflow/python/framework/ops.py in convert_to_tensor(value, dtype, name, preferred_dtype)
   1012       name=name,
   1013       preferred_dtype=preferred_dtype,
-> 1014       as_ref=False)
   1015 
   1016 

~/anaconda2/envs/py36/lib/python3.6/site-packages/tensorflow/python/framework/ops.py in internal_convert_to_tensor(value, dtype, name, as_ref, preferred_dtype, ctx)
   1102 
   1103     if ret is None:
-> 1104       ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
   1105 
   1106     if ret is NotImplemented:

~/anaconda2/envs/py36/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py in _constant_tensor_conversion_function(v, dtype, name, as_ref)
    233                                          as_ref=False):
    234   _ = as_ref
--> 235   return constant(v, dtype=dtype, name=name)
    236 
    237 

~/anaconda2/envs/py36/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py in constant(value, dtype, shape, name, verify_shape)
    212   tensor_value.tensor.CopyFrom(
    213       tensor_util.make_tensor_proto(
--> 214           value, dtype=dtype, shape=shape, verify_shape=verify_shape))
    215   dtype_value = attr_value_pb2.AttrValue(type=tensor_value.tensor.dtype)
    216   const_tensor = g.create_op(

~/anaconda2/envs/py36/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py in make_tensor_proto(values, dtype, shape, verify_shape)
    530     raise TypeError(
    531         "Element type not supported in TensorProto: %s" % numpy_dtype.name)
--> 532   append_fn(tensor_proto, proto_values)
    533 
    534   return tensor_proto

tensorflow/python/framework/fast_tensor_util.pyx in tensorflow.python.framework.fast_tensor_util.AppendObjectArrayToTensorProto()

~/anaconda2/envs/py36/lib/python3.6/site-packages/tensorflow/python/util/compat.py in as_bytes(bytes_or_text, encoding)
     65   else:
     66     raise TypeError('Expected binary or unicode string, got %r' %
---> 67                     (bytes_or_text,))
     68 
     69 

TypeError: Expected binary or unicode string, got 0.025550554

0 个答案:

没有答案