how to fix "unrecognized table variable name" error?

hi. i'm running a matlab code that extracts images and forms corresponding bounding boxes, but i get the following error:
"Error using trainextract (line 7)
Unrecognized table variable name 'imds'."
the code is as follows:
clear all
close all
clc
imds = imageDatastore('C:\Users\Muhammad Sanwal\Desktop\COMSATS\The 9th Semester (FA20)\FYP pt 1\MIO-TCD-Localization\train\00000000.jpg');
%%To import data from a CSV file into MATLAB use the “readtable” function. The “readtable” function automatically detects the header and the number of lines to skip
T = readtable('C:\Users\Muhammad Sanwal\Desktop\COMSATS\The 9th Semester (FA20)\FYP pt 1\MIO-TCD-Localization\test1.csv','ReadVariableNames',false);
getdata = T.imds;
the image under test is:
can someone please help me fix this error?
note: if someone will edit this code, he/she would have to write his own location where the image is stored.
the csv file is attached as well.

답변 (2개)

Walter Roberson
Walter Roberson 2021년 1월 21일
imds = imageDatastore('C:\Users\Muhammad Sanwal\Desktop\COMSATS\The 9th Semester (FA20)\FYP pt 1\MIO-TCD-Localization\train\00000000.jpg');
%%To import data from a CSV file into MATLAB use the “readtable” function. The “readtable” function automatically detects the header and the number of lines to skip
T = readtable('C:\Users\Muhammad Sanwal\Desktop\COMSATS\The 9th Semester (FA20)\FYP pt 1\MIO-TCD-Localization\test1.csv','ReadVariableNames',false);
[imgfound, imgidx] = ismember(T.Var1, imds.Files);
T.img = cell(height(T),1);
for K = 1 : length(imgfound)
if imgfound(K)
T.img{K} = readimage(imds, imgidx(K));
else
T.img{K} = zeros(0, 0, 3, 'uint8');
end
end
Any image listed in the csv and is present in the imds under the exact same name will have its T.img entry set to the content of the image; any file not located in the imds will have T.img set to an empty RGB image.

댓글 수: 2

it gives the following error:
Error using cell/ismember (line 34)
Input A of class double and input B of class cell must be cell arrays of character vectors, unless one is a character
vector.
Error in trainextract (line 4)
[imgfound, imgidx] = ismember(T.Var1, imds.Files);
T = readtable('test1.csv', 'readvariablenames', false)
T = 1x6 table
Var1 Var2 Var3 Var4 Var5 Var6 _____________________________________________________________________________________________________________________ __________________________________________________ _____________________ __________ __________ ____________________ {'C:\Users\Muhammad Sanwal\Desktop\COMSATS\The 9th Semester (FA20)\FYP pt 1\MIO-TCD-Localization\train\00000000.jpg'} {'"[194,78,273,122;155,27,183,35;106,32,124,45]"'} {'"[213,34,255,50]"'} {0×0 char} {0×0 char} {'"[43,25,109,55]"'}
T.Var1
ans = 1x1 cell array
{'C:\Users\Muhammad Sanwal\Desktop\COMSATS\The 9th Semester (FA20)\FYP pt 1\MIO-TCD-Localization\train\00000000.jpg'}
It does not come out as double as your error message indicates.

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

Jeremy Hughes
Jeremy Hughes 2021년 1월 21일

0 개 추천

'ReadVariableNames',false
This tells readtable not to read variable names from the file. So all the variable names will be "Var1","Var2",..., etc.
T.imds is trying to acces the variable named "imds" which doesn't exist.

댓글 수: 3

Even if i remove 'ReadVariableNames',false, when i run the code, the following warning appears along with the same error mentioned above:
"Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property. Set 'PreserveVariableNames' to true to use the original column headers as table variable names."
Yes, because "imds" is not a variable name in the table T.
It's hard to say what you need to do next, because it's not clear what data you're trying to get out of that table.
If you want to read the data in the image, you should be calling,
read(imds)

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

카테고리

도움말 센터File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

질문:

2021년 1월 21일

댓글:

2021년 1월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by