- maybe something else is wrong !
- maybe in your network connections to previous and next layer of your custom layer is not compatible !
Custom CNN layer Dot Indexing Issue?
2 views (last 30 days)
Show older comments
Hello!
I'm working on a CNN and I would like to be able to connect the output of a fully-connected layer to a convolutional layer. From some other "ask" pages, I read that a custom reshape layer is the solution for this. I have tried implementing one and I'm having some issues. When I use the checkLayer function, Matlab says everything is working. And when I insert the layer into my architecture and check it, Matlab doesn't throw any errors. However, when I try to train my CNN, I get the following error:
{Error using trainNetwork (line 184)
Dot indexing is not supported for variables of this type.
Error in trainDiscriminator (line 34)
[Disc_2, round1Data]=trainNetwork(trainData, trainLabels, Disc_2, trainOpts);
Caused by:
Dot indexing is not supported for variables of this type.
}
There's not really a way to determine if that's the custom layers' fault, but deleting them from the design did fix the error. I've also tested several similar architectures without the custom layers and none of them threw an error. For reference, the code for my reshape layer is as follows:
classdef reshapeLayer < nnet.layer.Layer
properties
rows;
cols;
end
properties (Learnable)
end
methods
function layer = reshapeLayer(name,rows,cols)
layer.Name = name;
layer.rows=rows;
layer.cols=cols;
end
function [Z] = predict(layer,X)
Z = reshape(X,layer.rows,layer.cols,1,[]);
end
end
end
Does anyone know how I can address this issue regarding the dot indexing of custom layers?
2 Comments
Abolfazl Chaman Motlagh
on 7 Sep 2021
Hi, i test your code. and it runs without error. i put your layer and test it on simple Cifar10 dataset.
mds = imageDatastore('images\cifar10Train\','LabelSource',"foldernames",'IncludeSubfolders',true,'ReadFcn',@(x) im2gray(imread(x)));
layers = [imageInputLayer([32 32 1],'Normalization',"none");
reshapeLayer('test',32,32);
fullyConnectedLayer(10);
softmaxLayer;
classificationLayer]
net = trainNetwork(imds,layers,options);
with some options. it start trainig without error.
Answers (0)
See Also
Categories
Find more on Image Data Workflows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!