神经网络之AlexNet模型的实现(Python+TensorFlow)
来源:互联网 发布:一搜同志个人网络 编辑:程序博客网 时间:2024/06/05 04:55
# -*- coding:utf-8 -*-## AlexNet modelimport tensorflow as tfimport numpy as npFLAGS = tf.app.flags.FLAGStf.app.flags.DEFINE_integer('num_class', 10, "number of classes.")#显示网络每一层结构的函数def print_layer(t): print(t.op.name, ' ', t.get_shape().as_list())def alexnet(images): # conv1 with tf.name_scope('conv1') as scope: kernel = tf.Variable(tf.truncated_normal([11,11,3,64], stddev=0.1), name='weights') biases = tf.Variable(tf.constant(0.0, shape=[64], trainable=True, name='biases') conv_plus_b = tf.nn.bias_add(tf.nn.conv2d(images, kernel, [1,4,4,1], padding='SAME'), biases) conv1 = tf.nn.relu(conv_plus_b, name=scope) print_layer(conv1) # LRN层, pool层 lrn1 = tf.nn.lrn(conv1, 4, bias=1.0, alpha=0.001/9, beta=0.75, name='lrn1') pool1 = tf.nn.max_pool(lrn1, ksize=[1,3,3,1], strides=[1,2,2,1], padding='VALID', name='pool1') # conv2 with tf.name_scope('conv2') as scope: kernel = tf.Variable(tf.truncated_normal([5,5,64,192], stddev=0.1), name='weights') biases = tf.Variable(tf.constant(0.0, shape=[192]), trainable=True, name='biases') conv_plus_b = tf.nn.bias_add(tf.nn.conv2d(pool1, kernel, [1,1,1,1], padding='SAME'), biases) conv2 = tf.nn.relu(conv_plus_b, name=scope) # LRN层, pool层 lrn2 = tf.nn.lrn(conv2, 4, bias=1.0, alpha=0.001/9, beta=0.75, name='lrn2') pool2 = tf.nn.max_pool(lrn2, ksize=[1,3,3,1], strides=[1,2,2,1], padding='VALID', name='pool2') # conv3 with tf.name_scope('conv3') as scope: kernel = tf.Variable(tf.truncated_normal([3,3,192,384], stddev=0.1), name='weights') biases = tf.Variable(tf.constant(0.0, shape=[384]), trainable=True, name='biases') conv_plus_b = tf.nn.bias_add(tf.nn.conv2d(pool2, kernel, [1,1,1,1], padding='SAME'), biases) conv3 = tf.nn.relu(conv_plus_b, name=scope) # conv4 with tf.name_scope('conv4') as scope: kernel = tf.Variable(tf.truncated_normal([3,3,384,256], stddev=0.1), name='weights') biases = tf.Variable(tf.constant(0.0, shape=[256]), trainable=True, name='biases') conv_plus_b = tf.nn.bias_add(tf.nn.conv2d(conv3, kernel, [1,1,1,1], padding='SAME'), biases) conv4 = tf.nn.relu(conv_plus_b, name=scope) # conv5 with tf.name_scope('conv5') as scope: kernel = tf.Variable(tf.truncated_normal([3,3,256,256], stddev=0.1), name='weights') biases = tf.Variable(tf.constant(0.0, shape=[256]), trainable=True, name='biases') conv_plus_b = tf.nn.bias_add(tf.nn.conv2d(conv4, kernel, [1,1,1,1], padding='SAME'), biases) conv5 = tf.nn.relu(conv_plus_b, name=scope) # pool5 pool5 = tf.nn.max_pool(conv5, ksize=[1,3,3,1], strides=[1,2,2,1], padding='VALID', name='pool5') # 卷积部分到此为止,分类问题的话还有3个全连接层: 4096,4096,num_class with tf.name_scope('fc1') as scope: input_shape = pool5.get_shape().as_list() input_units = np.prod(input_shape[1:]) W_fc1 = tf.Variable(tf.truncated_normal([input_units,4096], stddev=0.1, name='weight') b_fc1 = tf.Variable(tf.constant(0.1, shape=[4096]), name='bias') fc1 = tf.nn.relu(tf.matmul(tf.reshape(pool5, [-1,input_units]), W_fc1) + b_fc1, name=scope) fc1_drop = tf.nn.dropout(fc1, keep_prob) with tf.name_scope('fc2') as scope: W_fc2 = tf.Variable(tf.truncated_normal([4096,4096], stddev=0.1, name='weight') b_fc2 = tf.Variable(tf.constant(0.1, shape=[4096]), name='bias') fc2 = tf.nn.relu(tf.matmul(fc1_drop, W_fc2) + b_fc2, name=scope) fc2_drop = tf.nn.dropout(fc2, keep_prob) with tf.name_scope('fc3') as scope: W_fc3 = tf.Variable(tf.truncated_normal([4096,FLAGS.num_class], stddev=0.1, name='weight') b_fc3 = tf.Variable(tf.constant(0.1, shape=[FLAGS.num_class]), name='bias') out = tf.nn.softmax(tf.matmul(fc2_drop, W_fc3) + b_fc3) return out
阅读全文
0 0
- 神经网络之AlexNet模型的实现(Python+TensorFlow)
- AlexNet模型实现(4. 基于Tensorflow的python实现)
- 神经网络之VGGNet模型的实现(Python+TensorFlow)
- 神经网络之Inception模型的实现(Python+TensorFlow)
- 神经网络之ResNet模型的实现(Python+TensorFlow)
- 神经网络模型之AlexNet的一些总结
- 神经网络模型之AlexNet的一些总结
- AlexNet 的tensorflow 实现
- 【Deep Learning】tensorflow实现卷积神经网络(AlexNet)
- Tensorflow深度学习之十:Tensorflow实现经典卷积神经网络AlexNet
- 6经典卷积神经网络模型之AlexNet-6.1用于ImageNet的AlexNet网络计算图设计
- TensorFlow学习笔记(二十八)CNN的9大模型之AlexNet
- 基于tensorflow的AlexNet实现
- 机器学习实验(十二):深度学习之图像分类模型AlexNet结构分析和tensorflow实现
- 学习笔记TF052:卷积网络,神经网络发展,AlexNet的TensorFlow实现
- Tensorflow深度学习之二十二:AlexNet的实现(CIFAR-10数据集)
- 机器学习算法练习之(二):Python和Tensorflow分别实现简单的神经网络
- 6经典卷积神经网络模型之AlexNet-6.2用于ImageNet的AlexNet网络的假数据训练
- servlet 详解心得
- Server Tomcat v8.0 Server at localhost was unable to start within 45 seconds. If the server requires
- Dubbo基本原理机制 单一长连接
- 51Nod
- cordova调用相机
- 神经网络之AlexNet模型的实现(Python+TensorFlow)
- Mysql存储过程
- iOS的UICollectionView添加header
- 利用eclipse工具反向生成hibernate配置文件,domain类和映射文件
- eclipse快捷键
- hihocoder 最小生成树一·Prim算法
- Deep Reinforcement Learning 基础知识(DQN方面)
- 电脑触摸板失灵的处理方法
- Android安卓开发-eclipse正确添加第三方jar包