如何“翻译”数组来标记?
预测某个图像后,我得到了以下类:
np.argmax(classes, axis=2)
array([[ 1, 10, 27, 8, 2, 6, 6]])
我现在想将这些类转换为相应的字母数字。在使用此代码之前对我的类进行onehot编码(以便查看哪个类代表哪个字母/数字:
def my_onehot_encoded(label):
# define universe of possible input values
characters = '0123456789ABCDEFGHIJKLMNPQRSTUVWXYZ'
# define a mapping of chars to integers
char_to_int = dict((c, i) for i, c in enumerate(characters))
int_to_char = dict((i, c) for i, c in enumerate(characters))
# integer encode input data
integer_encoded = [char_to_int[char] for char in label]
# one hot encode
onehot_encoded = list()
for value in integer_encoded:
character = [0 for _ in range(len(characters))]
character[value] = 1
onehot_encoded.append(character)
return onehot_encoded
这意味着:类1
等于数字1
,类10
到 A
等等,我如何反转它并将数组转换为新标签
?
After predicting a certain image I got the following classes:
np.argmax(classes, axis=2)
array([[ 1, 10, 27, 8, 2, 6, 6]])
I now want to translate the classes to the corresponding letters numbers. To onehot encode my classes before I used this code (in order to see which class stands for which letter/number:
def my_onehot_encoded(label):
# define universe of possible input values
characters = '0123456789ABCDEFGHIJKLMNPQRSTUVWXYZ'
# define a mapping of chars to integers
char_to_int = dict((c, i) for i, c in enumerate(characters))
int_to_char = dict((i, c) for i, c in enumerate(characters))
# integer encode input data
integer_encoded = [char_to_int[char] for char in label]
# one hot encode
onehot_encoded = list()
for value in integer_encoded:
character = [0 for _ in range(len(characters))]
character[value] = 1
onehot_encoded.append(character)
return onehot_encoded
That means: class 1
is equal to number 1
, class 10
to A
and so on. How can I invert this and get the array to a new label?
Thanks a lot in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定我理解这个问题,但这可能有用吗?
输出:
如果你想要它作为字符串:
输出:
Not sure I understand the problem, but this might work?
output:
If you want it as a string:
output:
我得到以下输出:
I got the following output: