LeNet、AlexNet、VGG、ZF ゝ一纸荒年。 2022-08-23 00:56 170阅读 0赞 LeNet5 [LeNet模型理解][LeNet] CIFAR10 [CIFAR10模型理解简述 ][CIFAR10] ## AlexNet ## ### Caffe深度学习之图像分类模型AlexNet解读 ### 在imagenet上的图像分类challenge上Alex提出的alexnet网络结构模型赢得了2012届的冠军。要研究CNN类型DL网络模型在图像分类上的应用,就逃不开研究alexnet,这是CNN在图像分类上的经典模型(DL火起来之后)。 在DL开源实现caffe的model样例中,它也给出了alexnet的复现,具体网络配置文件如下 train\_val.prototxt 接下来本文将一步步对该网络配置结构中各个层进行详细的解读(训练阶段): 各种layer的operation更多解释可以参考 Caffe Layer Catalogue 从计算该模型的数据流过程中,该模型参数大概5kw+。 1. conv1阶段DFD(data flow diagram): ![Caffe 深度学习框架上手教程][Caffe] 2. conv2阶段DFD(data flow diagram):![Caffe 深度学习框架上手教程][Caffe 1] 3. conv3阶段DFD(data flow diagram): ![Caffe 深度学习框架上手教程][Caffe 2] 4. conv4阶段DFD(data flow diagram): ![Caffe 深度学习框架上手教程][Caffe 3] 5. conv5阶段DFD(data flow diagram): ![Caffe 深度学习框架上手教程][Caffe 4] 6. fc6阶段DFD(data flow diagram): ![Caffe 深度学习框架上手教程][Caffe 5] 7. fc7阶段DFD(data flow diagram): ![Caffe 深度学习框架上手教程][Caffe 6] 8. fc8阶段DFD(data flow diagram): ![Caffe 深度学习框架上手教程][Caffe 7] [AlexNet 之结构篇 ][AlexNet] [AlexNet 之算法篇][AlexNet 1] [AlexNet&Imagenet学习笔记][AlexNet_Imagenet] [ ][AlexNet 1] [CVPR 2015 之深度学习篇 Part 1 - AlexNet 和 VGG-Net][CVPR 2015 _ Part 1 _ AlexNet _ VGG-Net] [Alex / OverFeat / VGG 中的卷积参数][Alex _ OverFeat _ VGG] [TensorFlow实现AlexNet(forward和backward耗时计算)][TensorFlow_AlexNet_forward_backward] import input_data mnist = input_data.read_data_sets("/tmp/data/", one_hot=True) import tensorflow as tf # 定义网络超参数 learning_rate = 0.001 training_iters = 200000 batch_size = 64 display_step = 20 # 定义网络参数 n_input = 784 # 输入的维度 n_classes = 10 # 标签的维度 dropout = 0.8 # Dropout 的概率 # 占位符输入 x = tf.placeholder(tf.types.float32, [None, n_input]) y = tf.placeholder(tf.types.float32, [None, n_classes]) keep_prob = tf.placeholder(tf.types.float32) # 卷积操作 def conv2d(name, l_input, w, b): return tf.nn.relu(tf.nn.bias_add(tf.nn.conv2d(l_input, w, strides=[1, 1, 1, 1], padding='SAME'),b), name=name) # 最大下采样操作 def max_pool(name, l_input, k): return tf.nn.max_pool(l_input, ksize=[1, k, k, 1], strides=[1, k, k, 1], padding='SAME', name=name) # 归一化操作 def norm(name, l_input, lsize=4): return tf.nn.lrn(l_input, lsize, bias=1.0, alpha=0.001 / 9.0, beta=0.75, name=name) # 定义整个网络 def alex_net(_X, _weights, _biases, _dropout): # 向量转为矩阵 _X = tf.reshape(_X, shape=[-1, 28, 28, 1]) # 卷积层 conv1 = conv2d('conv1', _X, _weights['wc1'], _biases['bc1']) # 下采样层 pool1 = max_pool('pool1', conv1, k=2) # 归一化层 norm1 = norm('norm1', pool1, lsize=4) # Dropout norm1 = tf.nn.dropout(norm1, _dropout) # 卷积 conv2 = conv2d('conv2', norm1, _weights['wc2'], _biases['bc2']) # 下采样 pool2 = max_pool('pool2', conv2, k=2) # 归一化 norm2 = norm('norm2', pool2, lsize=4) # Dropout norm2 = tf.nn.dropout(norm2, _dropout) # 卷积 conv3 = conv2d('conv3', norm2, _weights['wc3'], _biases['bc3']) # 下采样 pool3 = max_pool('pool3', conv3, k=2) # 归一化 norm3 = norm('norm3', pool3, lsize=4) # Dropout norm3 = tf.nn.dropout(norm3, _dropout) # 全连接层,先把特征图转为向量 dense1 = tf.reshape(norm3, [-1, _weights['wd1'].get_shape().as_list()[0]]) dense1 = tf.nn.relu(tf.matmul(dense1, _weights['wd1']) + _biases['bd1'], name='fc1') # 全连接层 dense2 = tf.nn.relu(tf.matmul(dense1, _weights['wd2']) + _biases['bd2'], name='fc2') # Relu activation # 网络输出层 out = tf.matmul(dense2, _weights['out']) + _biases['out'] return out # 存储所有的网络参数 weights = { 'wc1': tf.Variable(tf.random_normal([3, 3, 1, 64])), 'wc2': tf.Variable(tf.random_normal([3, 3, 64, 128])), 'wc3': tf.Variable(tf.random_normal([3, 3, 128, 256])), 'wd1': tf.Variable(tf.random_normal([4*4*256, 1024])), 'wd2': tf.Variable(tf.random_normal([1024, 1024])), 'out': tf.Variable(tf.random_normal([1024, 10])) } biases = { 'bc1': tf.Variable(tf.random_normal([64])), 'bc2': tf.Variable(tf.random_normal([128])), 'bc3': tf.Variable(tf.random_normal([256])), 'bd1': tf.Variable(tf.random_normal([1024])), 'bd2': tf.Variable(tf.random_normal([1024])), 'out': tf.Variable(tf.random_normal([n_classes])) } # 构建模型 pred = alex_net(x, weights, biases, keep_prob) # 定义损失函数和学习步骤 cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(pred, y)) optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost) # 测试网络 correct_pred = tf.equal(tf.argmax(pred,1), tf.argmax(y,1)) accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32)) # 初始化所有的共享变量 init = tf.initialize_all_variables() # 开启一个训练 with tf.Session() as sess: sess.run(init) step = 1 # Keep training until reach max iterations while step * batch_size < training_iters: batch_xs, batch_ys = mnist.train.next_batch(batch_size) # 获取批数据 sess.run(optimizer, feed_dict={x: batch_xs, y: batch_ys, keep_prob: dropout}) if step % display_step == 0: # 计算精度 acc = sess.run(accuracy, feed_dict={x: batch_xs, y: batch_ys, keep_prob: 1.}) # 计算损失值 loss = sess.run(cost, feed_dict={x: batch_xs, y: batch_ys, keep_prob: 1.}) print "Iter " + str(step*batch_size) + ", Minibatch Loss= " + "{:.6f}".format(loss) + ", Training Accuracy= " + "{:.5f}".format(acc) step += 1 print "Optimization Finished!" # 计算测试精度 print "Testing Accuracy:", sess.run(accuracy, feed_dict={x: mnist.test.images[:256], y: mnist.test.labels[:256], keep_prob: 1.}) ## VGG ## [Very Deep Convolutional Networks for Large-Scale Image Recognition][] [Very Deep Convolutional Networks for Large-Scale Image Recognition][Very Deep Convolutional Networks for Large-Scale Image Recognition 1] [Very Deep Convolutional Networks for Large-Scale Image Recognition(VGG模型)][Very Deep Convolutional Networks for Large-Scale Image Recognition_VGG] [VGG-16 prototxt][] 网络结构 # -*- coding: utf-8 -*- import chainer from chainer import Variable import chainer.links as L import chainer.functions as F class VGGNet(chainer.Chain): """ VGGNet - It takes (224, 224, 3) sized image as imput """ def __init__(self): super(VGGNet, self).__init__( conv1_1=L.Convolution2D(3, 64, 3, stride=1, pad=1), conv1_2=L.Convolution2D(64, 64, 3, stride=1, pad=1), conv2_1=L.Convolution2D(64, 128, 3, stride=1, pad=1), conv2_2=L.Convolution2D(128, 128, 3, stride=1, pad=1), conv3_1=L.Convolution2D(128, 256, 3, stride=1, pad=1), conv3_2=L.Convolution2D(256, 256, 3, stride=1, pad=1), conv3_3=L.Convolution2D(256, 256, 3, stride=1, pad=1), conv4_1=L.Convolution2D(256, 512, 3, stride=1, pad=1), conv4_2=L.Convolution2D(512, 512, 3, stride=1, pad=1), conv4_3=L.Convolution2D(512, 512, 3, stride=1, pad=1), conv5_1=L.Convolution2D(512, 512, 3, stride=1, pad=1), conv5_2=L.Convolution2D(512, 512, 3, stride=1, pad=1), conv5_3=L.Convolution2D(512, 512, 3, stride=1, pad=1), fc6=L.Linear(25088, 4096), fc7=L.Linear(4096, 4096), fc8=L.Linear(4096, 1000) ) self.train = False def __call__(self, x, t): h = F.relu(self.conv1_1(x)) h = F.relu(self.conv1_2(h)) h = F.max_pooling_2d(h, 2, stride=2) h = F.relu(self.conv2_1(h)) h = F.relu(self.conv2_2(h)) h = F.max_pooling_2d(h, 2, stride=2) h = F.relu(self.conv3_1(h)) h = F.relu(self.conv3_2(h)) h = F.relu(self.conv3_3(h)) h = F.max_pooling_2d(h, 2, stride=2) h = F.relu(self.conv4_1(h)) h = F.relu(self.conv4_2(h)) h = F.relu(self.conv4_3(h)) h = F.max_pooling_2d(h, 2, stride=2) h = F.relu(self.conv5_1(h)) h = F.relu(self.conv5_2(h)) h = F.relu(self.conv5_3(h)) h = F.max_pooling_2d(h, 2, stride=2) h = F.dropout(F.relu(self.fc6(h)), train=self.train, ratio=0.5) h = F.dropout(F.relu(self.fc7(h)), train=self.train, ratio=0.5) h = self.fc8(h) if self.train: self.loss = F.softmax_cross_entropy(h, t) self.acc = F.accuracy(h, t) return self.loss else: self.pred = F.softmax(h) return self.pred [深度学习常用的Data Set数据集和CNN Model总结][Data Set_CNN Model] ## zf net ## [ZF-net][] [深度学习方法(五):卷积神经网络CNN经典模型整理Lenet,Alexnet,Googlenet,VGG,Deep Residual Learning][CNN_Lenet_Alexnet_Googlenet_VGG_Deep Residual Learning] [LeNet]: http://blog.csdn.net/lynnandwei/article/details/44082859 [CIFAR10]: http://blog.csdn.net/lynnandwei/article/details/44302175 [Caffe]: /images/20220722/eb650334b066471fa77fb3e2ccde5957.png [Caffe 1]: /images/20220722/6383b6be5bf34109af5a9a626d90de4a.png [Caffe 2]: /images/20220722/1a6df9526894478b858a9d9f523dc3a6.png [Caffe 3]: /images/20220722/1062ae6daae34c0f904fd2f069ecebda.png [Caffe 4]: /images/20220722/007442a84961449bb15c08550b8b7747.png [Caffe 5]: /images/20220722/0c55690714e24af58904ef3515e3f9e7.png [Caffe 6]: /images/20220722/c8500cfa8bcc45eeac234dec5d9d8cdc.png [Caffe 7]: /images/20220722/e2000edf8f724f258d7f45fb3b08ba84.png [AlexNet]: http://blog.sina.com.cn/s/blog_eb3aea990102v47i.html [AlexNet 1]: http://blog.sina.com.cn/s/blog_eb3aea990102v5px.html [AlexNet_Imagenet]: http://blog.csdn.net/lynnandwei/article/details/44411465 [CVPR 2015 _ Part 1 _ AlexNet _ VGG-Net]: http://www.ithao123.cn/content-8359874.html [Alex _ OverFeat _ VGG]: http://blog.csdn.net/ycheng_sjtu/article/details/47813039 [TensorFlow_AlexNet_forward_backward]: http://blog.csdn.net/superman_xxx/article/details/64442998 [Very Deep Convolutional Networks for Large-Scale Image Recognition]: http://blog.csdn.net/whiteinblue/article/details/43560491 [Very Deep Convolutional Networks for Large-Scale Image Recognition 1]: http://blog.csdn.net/stdcoutzyx/article/details/39736509 [Very Deep Convolutional Networks for Large-Scale Image Recognition_VGG]: http://blog.csdn.net/u014114990/article/details/50715548 [VGG-16 prototxt]: http://blog.csdn.net/baidu_24281959/article/details/52723666 [Data Set_CNN Model]: http://blog.csdn.net/qq_17448289/article/details/52850223 [ZF-net]: http://blog.csdn.net/chenyanqiao2010/article/details/50488075 [CNN_Lenet_Alexnet_Googlenet_VGG_Deep Residual Learning]: http://blog.csdn.net/xbinworld/article/details/45619685
还没有评论,来说两句吧...