pointnet train 第十句correct = tf.equal(tf.argmax(pred, 1), tf.to_int64(labels_pl))

correct = tf.equal(tf.argmax(pred, 1), tf.to_int64(labels_pl))

首先看tf.argmax(pred,1)因为pred,是32,40的tensor,40那一维是40个模型中对应的概率,取最大的一个索引作为预测值,最后得到shape 32的tensor然后跟shape 32的labels_pl相比,即tf.equal,得到32的tensor,类型为bool

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的卷积神经网络的代码,用于分类MNIST手写数字图像: ``` import tensorflow as tf # 定义输入和输出 x = tf.placeholder(tf.float32, [None, 784]) y_true = tf.placeholder(tf.float32, [None, 10]) # 将输入转换为28x28的图像 x_image = tf.reshape(x, [-1, 28, 28, 1]) # 定义第一层卷积层 conv1 = tf.layers.conv2d(inputs=x_image, filters=32, kernel_size=[5, 5], padding='same', activation=tf.nn.relu) # 定义第一层池化层 pool1 = tf.layers.max_pooling2d(inputs=conv1, pool_size=[2, 2], strides=2) # 定义第二层卷积层 conv2 = tf.layers.conv2d(inputs=pool1, filters=64, kernel_size=[5, 5], padding='same', activation=tf.nn.relu) # 定义第二层池化层 pool2 = tf.layers.max_pooling2d(inputs=conv2, pool_size=[2, 2], strides=2) # 将卷积层输出的张量转换为全连接层需要的形状 pool2_flat = tf.reshape(pool2, [-1, 7 * 7 * 64]) # 定义全连接层 dense = tf.layers.dense(inputs=pool2_flat, units=1024, activation=tf.nn.relu) # 添加dropout,防止过拟合 dropout = tf.layers.dropout(inputs=dense, rate=0.4) # 定义输出层 y_pred = tf.layers.dense(inputs=dropout, units=10) # 定义损失函数 cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y_true, logits=y_pred)) # 定义优化器 train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy) # 定义评估模型的准确率 correct_prediction = tf.equal(tf.argmax(y_pred, 1), tf.argmax(y_true, 1)) accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) # 初始化变量 init = tf.global_variables_initializer() # 加载MNIST数据集 mnist = tf.contrib.learn.datasets.load_dataset("mnist") # 将训练集和测试集分别存储为numpy数组 train_data = mnist.train.images train_labels = mnist.train.labels.astype(int) test_data = mnist.test.images test_labels = mnist.test.labels.astype(int) # 开始训练模型 with tf.Session() as sess: sess.run(init) for i in range(2000): batch_xs, batch_ys = mnist.train.next_batch(100) sess.run(train_step, feed_dict={x: batch_xs, y_true: batch_ys}) if i % 100 == 0: train_accuracy = accuracy.eval(feed_dict={x: batch_xs, y_true: batch_ys}) print("Step %d, training accuracy %g" % (i, train_accuracy)) test_accuracy = accuracy.eval(feed_dict={x: test_data, y_true: test_labels}) print("Test accuracy: %g" % test_accuracy) ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值