セマンティックセグメンテーションのトレーニング イメージとテスト イメージ
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
上のURLを参考に自分で用意したデータセットを用いてセマンティックセグメンテーションを行おうとしているのですが上のURLの学習セットとテスト セットの準備において,イメージとピクセル ラベル データを学習セットとテスト セットに無作為に分割する際,例えば,Aのイメージとピクセル ラベル データはテストセットにして残りを無作為に分けるといったことは可能なのでしょうか?
Accepted Answer
Kenta
on 21 Jan 2020
0 votes
こんにちは、以下のように、imnameで、自分の指定する画像Aの名前を打ち込んでください。
そのうえで、下の改訂版の補助関数を置けばできます。
下が確認のためのモンタージュ表示です。

imname='006900';
[imdsTrain, imdsVal, imdsTest, pxdsTrain, pxdsVal, pxdsTest] = partitionCamVidData_revised(imds,pxds,imname);
以下が改訂版の補助関数です。イメージデータストアから、自分の指定する画像を探し出して、
それのインデックスを最後に持ってこれば、テストデータに含めることができます。
function [imdsTrain, imdsVal, imdsTest, pxdsTrain, pxdsVal, pxdsTest] = partitionCamVidData_revised(imds,pxds,imname)
% Partition CamVid data by randomly selecting 60% of the data for training. The
% rest is used for testing.
% Set initial random state for example reproducibility.
rng(0);
numFiles = numel(imds.Files);
shuffledIndices = randperm(numFiles);
imLogical=contains(imds.Files,imname);
imIdex=find(imLogical==1);
imIdexDel=find(shuffledIndices==imIdex);
shuffledIndices(imIdexDel) = [];
shuffledIndices=[shuffledIndices,imIdex];
% Use 60% of the images for training.
numTrain = round(0.60 * numFiles);
trainingIdx = shuffledIndices(1:numTrain);
% Use 20% of the images for validation
numVal = round(0.20 * numFiles);
valIdx = shuffledIndices(numTrain+1:numTrain+numVal);
% Use the rest for testing.
testIdx = shuffledIndices(numTrain+numVal+1:end);
% Create image datastores for training and test.
trainingImages = imds.Files(trainingIdx);
valImages = imds.Files(valIdx);
testImages = imds.Files(testIdx);
imdsTrain = imageDatastore(trainingImages);
imdsVal = imageDatastore(valImages);
imdsTest = imageDatastore(testImages);
% Extract class and label IDs info.
classes = pxds.ClassNames;
labelIDs = camvidPixelLabelIDs();
% Create pixel label datastores for training and test.
trainingLabels = pxds.Files(trainingIdx);
valLabels = pxds.Files(valIdx);
testLabels = pxds.Files(testIdx);
pxdsTrain = pixelLabelDatastore(trainingLabels, classes, labelIDs);
pxdsVal = pixelLabelDatastore(valLabels, classes, labelIDs);
pxdsTest = pixelLabelDatastore(testLabels, classes, labelIDs);
end
11 Comments
Kodai Sato
on 21 Jan 2020
Kenta
on 21 Jan 2020
はい、もちろんラベルと画像のファイル名はちがうので、ファイル名(画像のほう)を指定すると、それに紐づいたラベルの画像((1).jpg)を自動に読みだして、操作するように作ってます。
Kodai Sato
on 21 Jan 2020
imname='1';
と入力すればよいのでしょうか?
Kenta
on 21 Jan 2020
imname='1.jpg'のほうがよさそうです
Kodai Sato
on 21 Jan 2020
丁寧にありがとうございました
Kodai Sato
on 9 Feb 2020
動かしてみたところ以下のようなエラーが発生しました
行列のインデックスは削除の範囲外です。
エラー: partitionCamVidData_revised (line 12)
shuffledIndices(imIdexDel) = [];
エラー: h_select_ver (line 2)
[imdsTrain, imdsVal, imdsTest, pxdsTrain, pxdsVal, pxdsTest] = partitionCamVidData_revised(imds,pxds,imname);
Kenta
on 9 Feb 2020
そちらの実行した状況がわからないのでなんともいえませんが、イメージデータストア内の画像が少なく、エラーを返したのかもしれません。こちらは画像を12枚ほど用意して実行した記憶があります。またコードをもとに、そちらの状況での原因を探っていただけると幸いです。
Kodai Sato
on 9 Feb 2020
データセットは1300枚で行っています.
Kenta
on 9 Feb 2020
そうですか...それでは枚数の問題ではなさそうですね。こちらのデータではうまくいきましたので、データの定義の仕方など軽微なものと思います。ただ、そちらの状況があまりわからないので、こちらでエラーを取るのはあまり効率がよくないと思います。今回のコードをオリジナルとして、kodai satoさまのほうで、原因解明や調整のほう、ご検討いただけないでしょうか?
Kodai Sato
on 9 Feb 2020
承知いたしました
ご丁寧にありがとうございました
もしかしたら、imnameが正しくないのかもしれません。テストに回したい画像が、1.jpgという名前なら、1.jpgか1とするなど、いろいろと試してみてください。そのほかの考えられる原因としては、pngになってるなど、拡張子が単にちがうだけかもしれません。
More Answers (0)
Categories
Find more on セマンティック セグメンテーション in Help Center and File Exchange
Tags
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)