2017-11-18 86 views
1

我使用下面的代碼,從文檔衍生的時:錯誤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]])

+0

你可以添加'features.shape','labels.shape'的輸出和每個的前幾行嗎? – Stephen

+0

嗨斯蒂芬,我更新了上面的帖子,回答你的問題。 –

回答

0

它看起來像這個問題實際上是在你的JSON文件。你的labels變量的輸出很好;你的features變量的輸出應該具有相同的結構,但它有一些list。如果您的JSON文件具有作爲屬性出現多次的「列表」,則應刪除這些文件及其圓括號(可能還有一些額外的方括號)。如果您自己生成了JSON,那麼在那裏進行更改可能更容易。

一個不相關的問題是你的標籤都是0;如果這不是你所期望的,那麼你可能在某處丟失了一些數據。