How to convert from structure to table?

Hi!
Hope everyone is doing well! I am following YOLO example for inferences with my own dataset. I noticed the example had annotations in the format like below in a table format (imagefilename cloumn, and vehicle column).
While the annotations file that I have has a different format and I am struggling to convert to the similar format as above. When I import the json file, it converts the data into stuct, which I am not very familiar with other than looking up Youtube videos, and MATLAB docs.
This is the data from imported json file.
This has multiple categories and each bounding box is split into individual rows. It seems I will have to convert that into a table format for corresponding image. I can have multiple columns for different categories. Any suggestions?
Thanks!

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 10월 26일

0 개 추천

You can use struct2table(): https://www.mathworks.com/help/releases/R2020b/matlab/ref/struct2table.html to convert structs to table. This shows how to access data in MATLAB's table: https://www.mathworks.com/help/matlab/matlab_prog/access-data-in-a-table.html

댓글 수: 5

Kev
Kev 2020년 10월 26일
편집: Kev 2020년 10월 26일
Here's my crude attempt at conversion:
I am thinking in terms of python syntax by wanting to iterate though column, but I feel like for MATLAB, it would be indicies?
vd2 = table();
for i = 1:3 % vd.image_id(end) %200
if vd.image_id(i) == i && vd.category_id(i) == 3 %vd is coverted to table from struct
vd2 = vd.bbox(i);
end
i = i+1;
end
the code doesn't work btw. I was trying to interate though image id 1 to 3 for example and make sure category id =3, if so, store the value in a new table. Eventually, I will have to make sure the new table for bbox column looks like this:
[202,190,132,122 ; 405, 193, 88, 77 ; 80, 220,48,28 ; 129, 219, 28, 34] - which corresponds to 1st image.
Kev
Kev 2020년 10월 27일
So, I have tried a lot of different ways to approach this problem. I was able to extract image id, category id, and bbox in a table format, but I wasn't getting the loop to work.
Another approach is that once I converted original struc2table, I used to following line to extract info from table itself:
rows = (vd.image_id == 0 & vd.category_id ==3);
vd(rows,:) and then I can extract bbox column which is 4x1 cell array
Now, after some conversion, I can get it to be 4x4 cell array, but I am not able to store it in a new table, like how the original dataset from the example is set up.
imagefile1 vehicle
1.jpg m by n matrix.
Any help is appreciated!
Kev
Kev 2020년 10월 27일
편집: Kev 2020년 10월 27일
After spending nearly 20 hours on this, I figured it out. :|
Ameer Hamza
Ameer Hamza 2020년 10월 29일
Sorry! I wasn't able to respond to this. Glad that you figured it out. You may consider sharing the solution so that it will be helpful for anyone else coming to this page.
Kev
Kev 2020년 10월 29일
sure, I will post the solution once I get the detector working so I know the code can be used in the future.

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

카테고리

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

질문:

Kev
2020년 10월 26일

댓글:

Kev
2020년 10월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by