CNN之tf.nn.softmax简单暴力带你学

CNN之tf.nn.softmax函数讲解

以下均在ubuntu20.04下完成,与之前版本略有所不同

import tensorflow.compat.v1  as tf
tf.compat.v1.disable_eager_execution()
x=tf.constant([[1.,2.,3.,4.,],[5.,6.,7.,8.],[9.,10.,11.,12.],[13.,14.,15.,16]])
x=tf.reshape(x,[2,2,4,1])#重新构建x的形状
num_features=a_shape[0:4].num_elements()#查看有多少数字
b=tf.reshape(x,[-1,num_features])#将所有数字写成一列,如下
v=tf.nn.softmax(b)#这个函数就是将所有的值进行归一化,即所有数的和为1
print(num_features)
with tf.Session() as sess:
	a5=sess.run(b)
	a6=sess.run(v)
	print(a5)
	print(a6)

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_51326570/article/details/112909259
今日推荐