Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 有没有解决办法可以将keras输入数据的列表发送到numpy数组?_Python_Arrays_Numpy_Keras - Fatal编程技术网

Python 有没有解决办法可以将keras输入数据的列表发送到numpy数组?

Python 有没有解决办法可以将keras输入数据的列表发送到numpy数组?,python,arrays,numpy,keras,Python,Arrays,Numpy,Keras,我想在keras上训练一个CNN模型,我的数据如下 type(datain) <class 'list'> len(datain) 35000 type(datain[0]) <class 'numpy.ndarray'> datain[0].shape (256,256,1) 但是,当尝试执行类似于此处建议的np.array(datain)之类的操作时,我的计算机冻结/崩溃。使用python list定义我的输入总共需要60秒,但是如果我从一开始就尝试使用numpy数

我想在keras上训练一个CNN模型,我的数据如下

type(datain)
<class 'list'>
len(datain)
35000
type(datain[0])
<class 'numpy.ndarray'>
datain[0].shape
(256,256,1)
但是,当尝试执行类似于此处建议的
np.array(datain)
之类的操作时,我的计算机冻结/崩溃。使用python list定义我的输入总共需要60秒,但是如果我从一开始就尝试使用numpy数组,但是每个
(256256,1)
数组需要1秒,如果我打算对我的网络进行各种测试和修改,那么时间太长了,
这个问题有解决办法吗?
有没有办法使用KERA列表?
定义numpy数组的另一种方法?

还是我误解了什么?

根据您的数据创建生成器

生成器是一个python概念,它循环并产生结果。对于KERA,您的生成器应无限期地生成批量的
X\u列
y\u列

因此,您可以制作一个简单的生成器:

def generator(batch_size,from_list_x,from_list_y):

    assert len(from_list_x) == len(from_list_y)
    total_size = len(from_list_x)

    while True #keras generators should be infinite

        for i in range(0,total_size,batch_size):
            yield np.array(from_list_x[i:i+batch_size]), np.array(from_list_y[i:i+batch_size])
在培训中使用发电机:

model.fit_generator(generator(size,datain,dataout),
                    steps_per_epoch=len(datain)//size, 
                    epochs=...,...)

从数据创建生成器

生成器是一个python概念,它循环并产生结果。对于KERA,您的生成器应无限期地生成批量的
X\u列
y\u列

因此,您可以制作一个简单的生成器:

def generator(batch_size,from_list_x,from_list_y):

    assert len(from_list_x) == len(from_list_y)
    total_size = len(from_list_x)

    while True #keras generators should be infinite

        for i in range(0,total_size,batch_size):
            yield np.array(from_list_x[i:i+batch_size]), np.array(from_list_y[i:i+batch_size])
在培训中使用发电机:

model.fit_generator(generator(size,datain,dataout),
                    steps_per_epoch=len(datain)//size, 
                    epochs=...,...)

这可能对计算机内存来说太多了。使用生成器。生成器是什么意思?请确定,首先尝试少量数据,如
np_data=np.array(datain[:100])
,然后查看错误是否仍然发生。好的,使用100,我的计算机没有冻结,我的网络开始训练这可能会占用您计算机的内存太多。使用生成器。你说的生成器是什么意思?只是为了确定,先尝试少量数据,比如
np_data=np.array(datain[:100])
,然后看看错误是否仍然发生。好的,使用100,我的计算机没有冻结,我的网络开始训练