How to create nnet.layers usable for custom training loops as well as trainNetwork?

1 回表示 (過去 30 日間)
Niklas
Niklas 2019 年 10 月 8 日
回答済み: Sai Bhargav Avula 2019 年 10 月 24 日
Hei all,
I would like to create a layer that can be pretrained in a custom training loop and afterwards finetuned with the trainNetwork function. I created a class with the needed properties and a predict function:
function Z = predict(layer, X)
Z = sigmoid(fullyconnect(X, layer.weights, layer.biases));
end
Using this function works fine during the pretraining. Using trainNetwork afterwards leads to the error:
Error using validateDataFormat (line 14)
Specify 'DataFormat' when first argument is an unlabeled dlarray or numeric array.
This is caused by fullyconnect as it needs dlarrays or the correct format string. I try to make it as universal as possible, so i don't want to set the Format property on the fullyconnect command. Is there a way to force trainNetwork to use dlarrays?
Thanks in advance,
Niklas

回答 (1 件)

Sai Bhargav Avula
Sai Bhargav Avula 2019 年 10 月 24 日
Hi,
As you mentioned the fullyconnect applies fully connect operation to dlarray data. For your custom layer to be made compactable to trainNetwork you should convert that using the fullyConnetedLayer by following template.
Or
You should finetune it by converting it into a dlnetwork.

カテゴリ

Help Center および File ExchangeCustom Layers についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by