【问题标题】:ds must be an imagedatasetds 必须是图像数据集
【发布时间】:2018-05-10 15:52:55
【问题描述】:

我正在尝试在我的图像数据集上实现 CNN。我的数据集包含 1100 个针对它们的响应变量条目。每个条目包含 81 张图像。这是我实现它的方式:

clear all
close all
clc

cd('E:\Project\Selected81\')
tbl = {'E:\Project\Selected81\00edff4f51a893d80dae2d42a7f45ad1', 1;
       'E:\Project\Selected81\0a0c32c9e08cc2ea76a71649de56be6d', 1;  
       'E:\Project\Selected81\0de72529c30fe642bc60dcb75c87f6bd', 0;
       'E:\Project\Selected81\1acbe17dc8f9f59d2fd167b2aa6c650f', 1};
options = trainingOptions('sgdm','InitialLearnRate',0.001,'MaxEpochs',15);
trainedNet = trainNetwork(tbl,5,options)

其中1101 分别是标签。

但它给出了以下错误:

ds 必须是图像数据集。

我不明白,因为我给出的路径是图像数据集。

更新代码:

myfolder = 'E:\Project\Selected81\00edff4f51a893d80dae2d42a7f45ad1'
myfolder1='E:\Project\Selected81\0a0c32c9e08cc2ea76a71649de56be6d'
myfolder2='E:\Project\Selected81\0de72529c30fe642bc60dcb75c87f6bd'
myfolder3='E:\Project\Selected81\1acbe17dc8f9f59d2fd167b2aa6c650f'
cd('E:\Project\Selected81\')
tbl = { datastore(myfolder, 'Type', 'image'), 1;
        datastore(myfolder1, 'Type', 'image'), 1;  
        datastore(myfolder2, 'Type', 'image'), 0;
        datastore(myfolder3, 'Type', 'image'), 1};

options = trainingOptions('sgdm','InitialLearnRate',0.001,'MaxEpochs',15);
trainedNet = trainNetwork(tbl,81,options)

我正在使用 MATLAB R2016b。

【问题讨论】:

  • 这也应该包括图像文件名。见doc
  • @SardarUsama 我无法给出每个图像路径。我用过datastore。请看一下,让我知道。
  • 您阅读过我在之前评论中引用的文档链接吗?
  • @SardarUsama 是的,这就是我想出更新代码的方式
  • 如果你读过那你应该知道你可以给出每张图片的路径

标签: matlab neural-network conv-neural-network


【解决方案1】:

正如错误消息所说,“ds 必须是一个图像数据集”,您所拥有的是图像目录的路径没有图像的名称。 p>

您需要使用datastoreimageDatastore

% Using myfolder, myfolder1, myfolder3 in one go since they have the same label
tbl = datastore({myfolder,myfolder1,myfolder3}, 'Type', 'image'); 
tbl2 = datastore(myfolder2, 'Type', 'image'); 
tbl.Files = {tbl.Files{:} tbl2.Files{:}}.';  %Combining the files
%                 Label is 1 ↓                   Label is 0 ↓    
Labels = categorical([repmat(1,1,length(tbl.Files)), repmat(0,1,length(tbl2.Files))]) ;
% Above line is for the general case. If you have 1 and 0 as labels, better use:
% [ones(1,length(tbl.Files))] and [zeros(1,length(tbl2.Files))]  respectively
tbl.Labels = Labels;   %Combining the labels
clear tbl2;            %Clearing tbl2 since it is not needed anymore

【讨论】:

    猜你喜欢
    • 2018-07-13
    • 1970-01-01
    • 1970-01-01
    • 2018-01-12
    • 2019-01-11
    • 1970-01-01
    • 1970-01-01
    • 2018-03-12
    • 1970-01-01
    相关资源
    最近更新 更多