categorical conversion to integer

I have trained a neural network with two classes (0 and 1)
When i input an image of size 256x256 as:
y=classify(net,input)
the output y is categorica (either 0 or 1)l.
When I type cast it int 8
y=cast(y,'int'8)
I ger wrong values. I need values as it is classified by classifier in categorical form (0 as 0, 1 as 1).
Any suggestion?
Thanks

답변 (3개)

Star Strider
Star Strider 2023년 4월 27일

1 개 추천

Perhaps something like this —
y = categorical([0 1])
y = 1×2 categorical array
0 1
y = cellfun(@str2double,categories(y))
y = 2×1
0 1
y = int8(y)
y = 2×1
0 1
.
Walter Roberson
Walter Roberson 2023년 4월 27일
편집: Walter Roberson 2023년 4월 28일

1 개 추천

create an ordinal categorical with valueset 0 and 1. Afterwards you can int8() the labels

댓글 수: 1

uint8() gives back the class number. If you ordered them then you can work on them mathematically.
y = categorical(randi([0 1], 10, 1), [0 1], ["0", "1"])
y = 10×1 categorical array
1 0 1 0 0 1 1 0 0 0
uint8(y) - 1
ans = 10×1
1 0 1 0 0 1 1 0 0 0

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

Stephen23
Stephen23 2023년 4월 27일

1 개 추천

M = categorical([0,1;1,0])
M = 2×2 categorical array
0 1 1 0
X = double(M);
Y = int8(str2double(categories(M)));
Z = Y(X)
Z = 2×2
0 1 1 0

카테고리

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

제품

릴리스

R2017b

질문:

2023년 4월 27일

댓글:

2023년 4월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by