Borrar filtros
Borrar filtros

trainNetwork의 코드에서 "훈련 또는 검증 응답 변수 데이터가 유효하지 않습니다. categorical형 응답 변수는 벡터이거나 단일채널 2차원 또는 3차원 영상이어야 합니다."가 어떤 이유로 오류인지 이유를 모르겠습니다.

8 visualizaciones (últimos 30 días)
재엽 정
재엽 정 el 30 de Jul. de 2022
Respondida: Himanshu el 27 de Sept. de 2023
이미 만들어져 있는 코드에서 불러오는 데이터만 변경되었습니다.
이미 만들어져 있는 코드에서 불러오는 데이터와 형식은 같지만 갯수만 다릅니다.
어떤 것이 문제인지 잘 모르겠습니다.
코드는 다음과 같습니다.
clear all;
close all;
clc;
%데이터를 저장하는 공간을 생성함
%이건 삼각형의 영상을 미리 훈련시키기 위한 것을 불러옴
dataSetDir = fullfile(toolboxdir('vision'),'visiondata','wearImages');
imageDir = fullfile(dataSetDir,'original image');
labelDir = fullfile(dataSetDir,'labeling image');
%훈련된 이미지를 저장하는 이미지데이터저장소를 생성함
imds = imageDatastore(imageDir);
%훈련하게되는 클래스 이름을 지정하고 라벨 ID를 생성하여 각각의 라벨ID를 지정할 수 있도록 함(정확한 답을 모르겠음)
%라벨 아이디 라는 것이 이미 지정되어 있는 데이터를 가져와서 쓰는 것이라고 판단이 됨.
classNames = ["wear","background"];
labelIDs = [200 0];
%훈련된 이미지에 대한 실측 픽셀 레이블을 저장하는 공간을 생성한다.
pxds = pixelLabelDatastore(labelDir,classNames,labelIDs);
%U-net Network를 생성한다.
%여기서 Unetlayer함수는 저장된 Deep Learning Toolbox에 의해서 함수를 끌어와서 사용하는 것임, 이과정 속에
%padding이나 convolution등등 모두 포함되어 있음
%이미지 사이즈는 임의로 결정이 된것임(실제 이미지의 높이-너비 순으로 대입할 수있음)
imageSize = [272 272];
numClasses = 2;
lgraph = unetLayers(imageSize, numClasses);
%Network에서 훈련된 내용을 저장하는 저장소를 만든다.
ds = combine(imds,pxds);
%훈련 옵션을 지정한다.
%훈련률을 0.001로 지정해주었음
%epoch는 전체 데이터 셋을 몇번돌면서 학습하는지에 대한 옵션,
options = trainingOptions('sgdm', ...
'InitialLearnRate',1e-3, ...
'MaxEpochs',20, ...
'VerboseFrequency',10);
%훈련한다.
net = trainNetwork(ds,lgraph,options);

Respuestas (1)

Himanshu
Himanshu el 27 de Sept. de 2023
Hello,
I understand that you are trying to train a U-Net Network with a specific set of images and labels. You encountered an error related to the validation response variable data. This error indicates that the categorical response variable must be a vector or a single-channel, two-dimensional or three-dimensional image.
The error might have occurred due to a mismatch between the data dimensions. Please make sure that your response variable data is in the correct format. It should be a vector or a single-channel 2D or 3D image.
You can follow the below steps to fix the issue.
  1. Verify the format of your response variable data. It should be a vector or a single-channel 2D or 3D image.
  2. Check the size and dimensions of your response variable data. It should match the input size and dimensions of your network.
  3. Validate the label IDs that you are using for training. Make sure they correctly correspond to the labels in your data.
  4. Validate the data you are using for training. Make sure it meets the requirements of the "trainNetwork" function.
You can refer to the below documentation to understand more about the "trainNetwork" function in MATLAB.

Community Treasure Hunt

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

Start Hunting!