Matrix dimension conversion for image input layer
6 次查看(过去 30 天)
显示 更早的评论
Hi
I have been working on a machine learning task where I have stuck at a point where I need to manage size of matrices for next computations. I am quite unsure how to do it or is it possible to do it..
Currently, I have a matrix, A of size 1000 x 768. I am going to fed this data as an input to the image input layer to train a network. I found that image input layert accepts input in the dimension of [x y z].
I would like to convert the data of A to [1 21 768] size. Is it possible to do such reshaping?
I have tried one of the way like this:
[a,b]=size(A)
newA=reshape(A.', 1,1,a,b)
But it turns out that the data was converted to 1 x 1 x 768 format which I am not looking for.
What should be the ideal solution of this?
thanks,
0 个评论
回答(1 个)
KALYAN ACHARJYA
2021-5-30
编辑:KALYAN ACHARJYA
2021-5-30
Sir, you can convert the size of the image from 2D to 3D using the following way (The image isualization is not affected)
ori_image=imread('file_name'); %Original Gray Image
image_modied=cat(3,ori_image,ori_image,ori_image); % Image with rxcxslices
"Currently, I have a matrix, A of size 1000 x 768. I am going to fed this data as an input to the image input layer to train a network. I found that image input layert accepts input in the dimension of [x y z]."
%A in [x,y] format
modified_data=cat(3,A,A,A); % [x,y,z] format
2 个评论
KALYAN ACHARJYA
2021-5-30
If you want to change 1000 x 768 to 1 x 21 x 768 using reshape, here number of the elements must be same? Are the input features remain invariaent after the operation?
Have you checked on pen and paper?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Algebra 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!