簡體   English   中英

Tensorflow 訓練在音頻分類器的第一個時期的最后一步崩潰

[英]Tensorflow Training Crashes in last step of first epoch for audio classifier

我試圖將最初用 Pytorch 編寫的自定義 DNN 網絡轉換為 Tensorflow 2 ,其輸入形狀要求為(batchsize,39,101,1)。 在使用特征提取器並獲得具有兼容維度的訓練和驗證數據集的維度(總樣本,39,101,1)之后,我嘗試使用 model.fit 訓練 model。 在第一個 epoch 的最后一步,我遇到了如下所示的錯誤,這表明我的張量形狀正在以某種方式發生變化。 我不知道為什么這只發生在最后一步。 我的回調非常簡單,與 model 檢查點和提前停止相關,如下所示。我的數據庫來自 Google Speech 數據集 v0.01。 我相信這是在驗證步驟開始之前發生的。 如果有人可以提供任何建議來解決它,那就太好了。

這是我的訓練和驗證數據集維度:

print(x_tr.shape) -> (17049, 39, 101, 1)
print(y_tr.shape) -> (17049, 10)
print(x_val.shape) -> (4263, 39, 101, 1)
print(y_val.shape) -> (4263, 10)
modelname, input_shape, numclass = 'CRNN', (39,101,1), 10

model = modelcreator.getmodel(modelname, input_shape, numclass)
es = EarlyStopping(monitor='val_loss', mode='min', verbose=1, patience=10, min_delta=0.0001) 
mc = ModelCheckpoint('best_model.hdf5', monitor='val_acc', verbose=1, save_best_only=True, mode='max')
history=model.fit(x_tr, y_tr ,epochs=100, callbacks=[es,mc], batch_size=64, validation_data=(x_val,y_val))

紀元 1/100 266/267 [=============================>.] - ETA:0s - 損失:0.9436 - 准確度: 0.6963

-------------------------------------------------- ------------------------- InvalidArgumentError Traceback (最近一次調用最后一次) in ----> 1 history=model.fit(x_tr, y_tr, epochs=100,回調=[es,mc],batch_size=64,validation_data=(x_val,y_val))

~/Desktop/Spoken_Keyword_Spotting/newenv/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py in _method_wrapper(self, *args, **kwargs) 106 def _method_wrapper(self, *args, **kwargs): 107 if not self._in_multi_worker_mode(): # pylint: disable=protected-access --> 108 return method(self, *args, **kwargs) 109 110 # 已經在run_distribute_coordinator內部運行。

~/Desktop/Spoken_Keyword_Spotting/newenv/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle,class_weight,sample_weight,initial_epoch,steps_per_epoch,validation_steps,validation_batch_size,validation_freq,max_queue_size,workers,use_multiprocessing)1096 batch_size=batch_size):
1097 callbacks.on_train_batch_begin(step) -> 1098 tmp_logs = train_function(iterator) 1099 if data_handler.should_sync: 1100
context.async_wait()

~/Desktop/Spoken_Keyword_Spotting/newenv/lib/python3.6/site-packages/tensorflow/python/eager/def_function.py in call (self, *args, **kwds) 778 else: 779 compiler = "nonXla" -- > 780 結果 = self._call(*args, **kwds) 781 782 new_tracing_count = self._get_tracing_count()

~/Desktop/Spoken_Keyword_Spotting/newenv/lib/python3.6/site-packages/tensorflow/python/eager/def_function.py in _call(self, *args, **kwds) 805 # 在這種情況下,我們已經在第一次調用,所以我們運行 806 # defunned 版本,它保證永遠不會創建變量。 --> 807 return self._stateless_fn(*args, **kwds) # pylint: disable=not-callable 808 elif self._stateful_fn is not None: 809 # 提前釋放鎖,讓多個線程可以執行調用

~/Desktop/Spoken_Keyword_Spotting/newenv/lib/python3.6/site-packages/tensorflow/python/eager/function.py in call (self, *args, **kwargs) 2827 with self._lock:
2828 graph_function, args, kwargs = self._maybe_define_function(args, kwargs) -> 2829 return graph_function._filtered_call(args, kwargs) #pylint: disable=protected-access 2830 2831 @property

~/Desktop/Spoken_Keyword_Spotting/newenv/lib/python3.6/site-packages/tensorflow/python/eager/function.py in _filtered_call(self,args,kwargs,cancellation_manager)1846
resource_variable_ops.BaseResourceVariable))],1847
capture_inputs=self.captured_inputs,-> 1848 cancel_manager=cancellation_manager)1849 1850 def _call_flat(self,args,captured_inputs,cancellation_manager=None):

~/Desktop/Spoken_Keyword_Spotting/newenv/lib/python3.6/site-packages/tensorflow/python/eager/function.py in _call_flat(self,args,capped_inputs,cancellation_manager)
1922 # 沒有磁帶在看; 跳至運行 function。
1923年返回self._build_call_outputs(self._inference_function.call(-> 1924 ctx,args,cancellation_manager=cancellation_manager))1925
forward_backward = self._select_forward_and_backward_functions(
1926 參數,

~/Desktop/Spoken_Keyword_Spotting/newenv/lib/python3.6/site-packages/tensorflow/python/eager/function.py 在調用中(self,ctx,args,cancellation_manager) 548 個輸入=args,549 個 attrs=attrs,- > 550 ctx=ctx) 551 else: 552 輸出 = execute.execute_with_cancellation(

~/Desktop/Spoken_Keyword_Spotting/newenv/lib/python3.6/site-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name) 58 ctx.ensure_initialized() 59 張量= pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name, ---> 60 個輸入, attrs, num_outputs) 61 除了 core._NotOkStatusException 作為 e: 62 如果名稱不是 None:

InvalidArgumentError:從形狀為 [25,512] [[{{node TensorArrayUnstack/TensorListFromTensor}}]] 的張量中指定形狀為 [64,512] 的列表
[[functional_3/lstm_1/PartitionedCall]] [Op:__inference_train_function_13255]

Function 調用堆棧:train_function -> train_function -> train_function

我是從下面的鏈接中想到的。 基於此處的答案: InvalidArgumentError: Specified a list with shape [60,9] from a tensor with shape [56,9]

我的 model 最后由一個 LSTM 層組成,返回序列 = True。 因此,在最后一個時期,接收到的批次的樣本少於批次大小。 遇到了這個問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM