0
我在张量流中很慢的批量加载时遇到问题。 训练中的每一步都相当快,但是我的加载数据的功能非常缓慢。如何在张量流中优化批量加载?
我想知道是否有任何方法可以使这个速度更快,或者当列车运行正在运行时在后台运行它,以便在完成一个步骤时可以准备批次。
我的功能存储在numpy数组中。
任何想法? 这是我的代码。
def test_loadbatch(no_timesteps,list_of_file_paths,batch_size):
nof=no_timesteps# No of combined
files=list_of_file_paths
files=shuffle_list(files)
classes=get_class_number(files)
temp_batch=np.zeros(shape=(batch_size,no_timesteps,4096),dtype=np.float32)
temp_classes=np.zeros(shape=(batch_size,101),dtype=np.float32)
bat_num=0
fileno=0
while bat_num != batch_size :
if os.path.isfile(str(files[fileno])):
val=np.load(str(files[fileno]))
try:
if val.shape[0]>no_timesteps+2:
num=random.randint(0,val.shape[0]-(no_timesteps+2))
temp_batch[bat_num,:,:]=val[num:num+nof,:]
temp_classes[bat_num,:]=create_one_hot(classes[fileno])
bat_num=bat_num+1
except Exception as ex:
fileno=fileno+1
fileno=fileno+1
return np.maximum(np.tanh(temp_batch), 0),temp_classes #normalize in range 0->1
你可以用cProfile运行它并查看使用snakeviz花费的时间吗? –
不错的想法..看起来像大多数时间花在npyio上它从磁盘读取文件..我不知道我怎么能减少此..将通过FIFOqueue,看看如果我可以实现的东西.. .. –