Why does "checkLayer" hang? Or use "checkLayer" to report errors after modification,how do I modify my custom layer?

1 次查看(过去 30 天)
When I write a custom "upsample2dLayer" layer and use the "checkLayer" function to check its validity, the program always hangs without error. How can I solve it?
classdef upsample2dLayer < nnet.layer.Layer
properties
size
isplus %bool值,表明是否上采样后特征图大小+1,引入是为了防止特征图相加维度大小不匹配
end
methods
function layer = upsample2dLayer(size,name,isplus)
arguments
size (1,1) double
name (:,:) char = 'up2dsample layer'
isplus (1,1) logical = false
end
layer.Name = name;
text = [num2str(size),' upsampling for YOLOv3'];
layer.Description = text;
layer.Type = 'UpSample2d';
layer.size = size;
layer.isplus = isplus;
end
function Z = predict(layer, X)
Z = repelem(X, layer.size, layer.size);
% if layer.isplus
% Z(end+1,:) = Z(end,:);
% Z(:,end+1) = Z(:,end);
% end
end
function [dX] = backward( layer, X, ~, dZ, ~ )
dX = dZ(1:layer.size:end, 1:layer.size:end, :, :);
end
end
end
%%
% 参考:https://ww2.mathworks.cn/matlabcentral/fileexchange/71277-deep-learning-darknet-importer
% 官方文档:Define Custom Deep Learning Layers
Then use "checkLayer" as follows:
testL = upsample2dLayer(2,'kkk',true);
validSize = [24,24,256];
checkLayer(testL,validSize)
Always hanging?
*********************************************************************************************************
Then I did not comment the 4 lines in the predict function, and then performed a checkLayer check to report an error, but I can't understand the meaning of the error. How can I modify the predict function?
Running nnet.checklayer.TestLayerWithBackward
.
================================================================================
Verification failed in nnet.checklayer.TestLayerWithBackward/predictDoesNotError(Observations=one).
---------------------
Framework Diagnostic:
---------------------
The function 'predict' threw an error:
------------------
Stack Information:
------------------
In C:\Program Files\MATLAB\R2020a\toolbox\nnet\cnn\+nnet\+checklayer\TestLayerWithBackward.m (TestLayerWithBackward.predictDoesNotError) at 24
(The following output is omitted)
So, after reading the official documentation, I still don't know how to do it, how can I modify my custom layer?

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by