【问题标题】:How to reshape input data for tflearn?如何重塑 tflearn 的输入数据?
【发布时间】:2018-10-07 00:03:11
【问题描述】:

我正在尝试重塑我的数据以与 tflearn 兼容,我的数据中的每一行都是形状 (1300, 13)。因此,在我加载数据并将这些 (1300, 13) 形状的行中的每一个放入一个像这样的 numpy 数组中之后:

data_path = os.path.dirname(os.path.realpath(__file__)) + '/../data/data.csv'
train = data.sample(frac=0.8, random_state=200)
test = data.drop(train.index)

train_x = train['lowLevel.mfcc'].as_matrix()
test_x = test['lowLevel.mfcc'].as_matrix()

print(train_x.shape) # (8,)
print(train_x[0].shape) # (1300, 13)


train_y = to_categorical(train['category'], len(categories))
test_y = to_categorical(test['category'], len(categories))

train_x = train_x.reshape([-1, 1300, 13, 1])
test_x = test_x.reshape([-1, 1300, 13, 1])

# ValueError: cannot reshape array of size 8 into shape (1300,13,1)

不知道在这里做什么,我从文档中复制MNIST tutorial: 他们的数据分别是形状 train_x train_y test_x test_y (55000, 10) (55000, 10) (10000, 784) (10000, 10)

我的数据的形状是这样的(只加载 10 行,直到我让它工作): (8,) (8, 1) (2,) (2, 1) 当我打印train_x 时,它看起来像这样:

不确定所有数组是怎么回事,因为我告诉 Pandas 将列加载为矩阵...

MNIST 数据可以像这样完美重塑:

train_x, train_y, test_x, test_y = mnist.load_data(one_hot=True)

train_x = train_x.reshape([-1, 28, 28, 1])
test_x = test_x.reshape([-1, 28, 28, 1])

我正在从 pandas 数据框中加载我的数据,但不知道如何塑造它。

我在 tflearn 中这样设置输入层:

import tflearn
from tflearn.layers.core import input_data
from tflearn.data_utils import to_categorical

net = input_data(shape=[None, 1300, 13, 1], name='input')

有人知道发生了什么吗?

【问题讨论】:

    标签: python pandas numpy tflearn


    【解决方案1】:

    想通了,不得不预先分配数组:

    train_x = np.empty((train['lowLevel.mfcc'].size, 1300, 13))
    test_x = np.empty((test['lowLevel.mfcc'].size, 1300, 13))
    
    for index, item in enumerate(train['lowLevel.mfcc']):
        train_x[index] = item
    
    for index, item in enumerate(test['lowLevel.mfcc']):
        test_x[index] = item
    

    【讨论】:

      猜你喜欢
      • 2017-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-26
      • 1970-01-01
      • 2018-06-05
      • 1970-01-01
      相关资源
      最近更新 更多