【发布时间】:2017-11-18 01:04:08
【问题描述】:
我正在使用以下代码,源自文档:
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np
import json
from pprint import pprint
with open('/root/ml/2017110508.training.json') as text:
data = json.load(text)
features = np.array(data['input']['values'])
labels = np.array(data['output']['values'])
pprint(features.shape)
pprint(labels.shape)
pprint(features[0:3])
pprint(labels[0:3])
# Assume that each row of `features` corresponds to the same row as `labels`.
assert features.shape[0] == labels.shape[0]
dataset = tf.data.Dataset.from_tensor_slices((features, labels))
data['input']['values'] 和 data['output']['values'] 中的数据只是浮点数行,但我得到:
TypeError: 预期的二进制或 unicode 字符串,得到 [0.6, 0.0, 0.6, 0.0, 0.0、0.0、0.0、0.3、0.6、1.5、0.0、0.4、7.7、-8.5、158.0、6.2、55.3、203.4、205.7、156.5、-8.5、7.3、-8.8、53.5、-0.9、-31.2、15.3 , -1.9, -87.6, 21.3, -21.6, -34.7, -17.1, -85.0, 28.6, -19.1]
from_tensor_slices需要什么格式?
谢谢。
pprint 调用的输出:
(58502,)
(58502, 5)
array([ list([0.6, 0.0, 0.6, 0.0, 0.0, 0.0, 0.0, 0.3, 0.6, 1.5, 0.0, 0.4、7.7、-8.5、158.0、6.2、55.3、203.4、205.7、156.5、-8.5、7.3、-8.8、53.5、-0.9、-31.2、15.3、-1.9、-87.6、21.3、-21.6、-34.7 , -17.1, -85.0, 28.6, -19.1]), list([1.3, 0.0, 1.2, 0.0, 0.0, 0.0, 0.0, 0.6, 1.0, 2.3, 0.0, 0.6, 7.7, -8.5, 158.0, 6.2, 55.3, 203.4, 205.7, 156.4, -8.5, 7.5, - 8.8、53.4、-0.9、-31.2、15.3、-1.9、-87.6、21.3、-21.6、-34.7、-17.0、-85.0、28.6、-19.1]), list([2.0, 0.0, 1.6, 0.0, 0.0, 0.0, 0.2, 0.8, 1.1, 2.9, 0.0, 0.9, 8.0, -8.5, 158.2, 6.2, 55.3, 203.4, 205.7, 156.3, -8.5, 8.0, - 8.8、53.3、-0.9、-31.2、15.1、-1.9、-87.6、21.3、-21.6、-34.8、-16.8、-84.9、28.6、-19.1])]、dtype=object)
数组([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
【问题讨论】:
-
你能把
features.shape、labels.shape的输出加上每个的前几行吗? -
嗨斯蒂芬,我更新了上面的帖子,回答了你的问题。
标签: json tensorflow