我使用下面的代碼,從文檔衍生的時:錯誤Tensorflow使用JSON導出的數據
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))
在數據中的數據[「輸入」] [「值」]和數據['輸出'] [' 值]只是彩車行,但我得到:
TypeError: Expected binary or unicode string, got [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)
array([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
你可以添加'features.shape','labels.shape'的輸出和每個的前幾行嗎? – Stephen
嗨斯蒂芬,我更新了上面的帖子,回答你的問題。 –