ValueError:无法将大小为10的数组重塑为形状(10,3,32,32)

时间:2019-02-20 17:52:29

标签: arrays python-3.x numpy

我收到重塑错误,但不确定如何解决。到目前为止,这是我所做的。有什么建议我做错了吗?谢谢!

import pickle
import numpy as np
import matplotlib.pyplot as plt
import os

dataset_folder_path = 'cifar-10-batches-py'

labels = []
data = []
alllabels = []
alldata = []

    for i in range(1,6): 
        print("procesing file ", '/data_batch_' + str(i))
        with open(dataset_folder_path + '/data_batch_' + str(i), mode='rb')as file:
        my_data = (pickle.load(file, encoding='latin1'))        
        labels = my_data['labels']
        alllabels = np.append(alllabels,labels)

        data = my_data['data']
        alldata = np.append(alldata, data)


   def getbatch(alldata, alllabels, batch_size = 16):
        print(batch_size)
        for start in range(0, len(alldata), batch_size):
            end = min(start + batch_size, len(alldata))
            yield (alldata[start:end], alllabels[start:end])


    batchsize = 10
    for x, y in getbatch(alldata, alllabels, batchsize):
        x = x.reshape(batchsize, 3, 32, 32)    

0 个答案:

没有答案