def data_gen(filename,dic_len,batch_size):
with h5py.File(filename,'r') as f:
datas,labels=f['x'][:],f['y'][:]
nb_samples=datas.shape[0]
index_max=nb_samples-batch_size
while 1:
start=int(np.random.randint(index_max,size=1))
data=datas[start:start+batch_size]
label=to_categorical(labels[start:start+batch_size],dic_len)
label=label.astype('int8').reshape((batch_size,-1,label.shape[-1]))
yield (data,label)
generators.py 文件源码
python
阅读 27
收藏 0
点赞 0
评论 0
评论列表
文章目录