How to pull the data value from a 1x1 struct with 12 fields and store that for corresponding images in a pixelLabelDatastore?

조회 수: 7(최근 30일)
Hey i'm trying to read in volumes to ultimately train a network but im encountering this error:
Error using trainNetwork (line 183)
The output of the custom ReadFcn must be a categorical matrix.
Error in praxisNetwork1_0 (line 40)
net = trainNetwork(ds,lgraph,options)
Caused by:
Error using (line 309)
The output of the custom ReadFcn must be a categorical matrix.
I'm reading in .nrrd files for the pixelLabelDatastore and manage to read them in with the mathworks .nrrd reader however I can't seem to get just the data field of the struct that gets read in. I believe the categorical matrix error is occurring because the network attempts to utilize this struct field instead of the categorical matric that is the data field. This issue doesnt appear when I read in the training images because those files came as .mha's which are read in as categorical matrices. Any ideas or suggestions are appreciated.

채택된 답변

Raunak Gupta
Raunak Gupta 2020년 11월 13일
From seeing all the code files attached in the code, I see that nha_read_volume returns a volume which can be used as training image whereas nhdr_nrrd_read returns a structure which contains many fields and information about the whole file. Since the ReadFcn should return a categorical array to use in pixelLabelDatastore, I will suggest creating a separate ReadFcn which uses nhdr_nrrd_read to read the strcuture from raw file and then select the data field out of the structure. Also make sure to convert the data into categorical array as I mentioned in a similar question and the structure contains the data field.
An example for that ReadFcn
function data = readNRRD(filename)
nrrdHeader = nhdr_nrrd_read(filename,true);
data = categorical(;
  댓글 수: 2
Raunak Gupta
Raunak Gupta 2020년 12월 31일
Hi Xavier,
I understand that a label file with exact categories like "background" and "kidney" is not present but I assume for supervised classification a label file will be there. I do think that the label file will be seperate from the data file. If the labels are there and have the same format it can be read with the same method. Generally if its a label file then it will in binary format containing 0s and 1s. You can replace the 0s and 1s with particular string labels and that will make it suitable for passing into pixelLabelDatastore.
Syntax for replacing:
labelsCat = categorical(labelsBinary,[0,1],{'background','kidney'});
Here the "background" will be assigned in place of 0s and "kidney" will be assigned to 1s.
If there are more labels the vector and cell array can be extended.
As for the last question I think the categories present in data must be encoded into "kinds" field of the struct but I am not sure since I haven't worked with this data.
Hope this helps!

댓글을 달려면 로그인하십시오.

추가 답변(0개)





Community Treasure Hunt

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

Start Hunting!

Translated by