1

我工作的一個腦損傷分割的問題,我試圖實現與代碼UNET啓發:https://github.com/jocicmarko/ultrasound-nerve-segmentationKeras sample_weight陣列錯誤

一個我試圖克服的問題是職業平衡(更多的非病變體素而不是病變體素)。我嘗試使用class_balance,但沒有工作,所以現在我試圖使用sample_weight,這也給了我各種各樣的錯誤。

我試圖第一件事是設置sample_weight_modetemporal並且以相同的形狀的權重矩陣飼料作爲我的目標數據:

target_data.shape -> (n_samples,512 rows/pixels, 512 cols/pixels, 1 channel) 
Weight_map.shape -> (n_samples,512 rows/pixels, 512 cols/pixels, 1 channel) 

輸出:

_ValueError: Found a sample_weight array with shape (100, 512, 512, 1). In order to use timestep-wise sample weighting, you should pass a 2D sample_weight array.*

我試圖第二件事是將樣品陣列弄平以使其變形:

Weight_map.shape -> (n_samples,512x512x1). 

輸出:

ValueError: Found a sample_weight array with shape (100, 262144) for an input with shape (100, 512, 512, 1). sample_weight cannot be broadcast.*

接着我試圖以下uschmidt83(here),並與相應的目標數據沿着平坦化我的模型的輸出的意見。

last_layer = keras.layers.Flatten()(second_last_layer) 

target_data.shape -> (n_samples,512x512x1). 
Weight_map.shape -> (n_samples,512x512x1). 

輸出:

ValueError: Found a sample_weight array for an input with shape (100, 262144). Timestep-wise sample weighting (use of sample_weight_mode="temporal") is restricted to outputs that are at least 3D, i.e. that have a time dimension.*

奇怪的是,即使我設置sample_weight=None我仍然得到同樣的錯誤正上方。

有關如何解決此sample_weight錯誤的任何建議?這裏是重現錯誤的基本代碼: https://gist.github.com/andreimouraviev/2642384705034da92d6954dd9993fb4d

此外,如果您有關於如何處理類不平衡問題的建議,請讓我知道。

回答

0

重量需要是一維數組,其中目標有一個額外的通道,如輸入。

你可以嘗試用sample_weight_mode=temporal以下尺寸:

input_image -> (n_samples, 512, 512, 1) 
target_label -> (n_samples, 262144, 1) 
weight_map -> (n_samples, 262144) 

以下鏈接包含有關類權重信息: https://github.com/fchollet/keras/issues/2115