# 目录

## 参考资料

 产生背景

 工作原理

out = np.array([[4.0, 5.0, 10.0], [1.0, 5.0, 4.0], [1.0, 15.0, 4.0]])

y = np.array([[0, 0, 1], [0, 1, 0], [0, 1, 0]])

res = tf.losses.softmax_cross_entropy(onehot_labels=y, logits=out, label_smoothing=0)

print(tf.Session().run(res))

res2 = tf.losses.softmax_cross_entropy(onehot_labels=y, logits=out, label_smoothing=0.001)

print(tf.Session().run(res2))

# new_onehot_labels = onehot_labels * (1 - label_smoothing) + label_smoothing / num_classes

new_onehot_labels = y * (1 - 0.001) + 0.001 / 3

print(y)

print(new_onehot_labels)

[[0 0 1]

[0 1 0]

[0 1 0]]

[[3.33333333e-04 3.33333333e-04 9.99333333e-01]

[3.33333333e-04 9.99333333e-01 3.33333333e-04]

[3.33333333e-04 9.99333333e-01 3.33333333e-04]]

res3 = tf.losses.softmax_cross_entropy(onehot_labels=new_onehot_labels, logits=out, label_smoothing=0)

print(tf.Session().run(res3))

import numpy as np
import tensorflow as tf

out = np.array([[4.0, 5.0, 10.0], [1.0, 5.0, 4.0], [1.0, 15.0, 4.0]])
y = np.array([[0, 0, 1], [0, 1, 0], [0, 1, 0]])

res = tf.losses.softmax_cross_entropy(onehot_labels=y, logits=out, label_smoothing=0)
print(tf.Session().run(res))

res2 = tf.losses.softmax_cross_entropy(onehot_labels=y, logits=out, label_smoothing=0.001)
print(tf.Session().run(res2))

# new_onehot_labels = onehot_labels * (1 - label_smoothing)
#                           + label_smoothing / num_classes

new_onehot_labels = y * (1 - 0.001) + 0.001 / 3
print(y)
print(new_onehot_labels)
res3 = tf.losses.softmax_cross_entropy(onehot_labels=new_onehot_labels, logits=out, label_smoothing=0)
print(tf.Session().run(res3))
View Code

 参考资料

Rethinking the Inception Architecture for Computer Vision

https://www.datalearner.com/blog/1051561454844661

posted @ 2019-07-27 11:48  黎明程序员  阅读(7922)  评论(0编辑  收藏  举报