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,看看如果我可以實現的東西.. .. –