aihot  2017-12-04 10:44:53  机器学习 |   查看评论   

  在tensorflow构造GoogLeNet基本的代码:

 

  from kaffe.tensorflow import Network

 

  class GoogleNet(Network):

 

  1.  def setup(self):
  2.      (self.feed('data')
  3.           .conv(7, 7, 64, 2, 2, name='conv1_7x7_s2')
  4.           .max_pool(3, 3, 2, 2, name='pool1_3x3_s2')
  5.           .lrn(2, 2e-05, 0.75, name='pool1_norm1')
  6.           .conv(1, 1, 64, 1, 1, name='conv2_3x3_reduce')
  7.           .conv(3, 3, 192, 1, 1, name='conv2_3x3')
  8.           .lrn(2, 2e-05, 0.75, name='conv2_norm2')
  9.           .max_pool(3, 3, 2, 2, name='pool2_3x3_s2')
  10.           .conv(1, 1, 64, 1, 1, name='inception_3a_1x1'))

  11.      (self.feed('pool2_3x3_s2')
  12.           .conv(1, 1, 96, 1, 1, name='inception_3a_3x3_reduce')
  13.           .conv(3, 3, 128, 1, 1, name='inception_3a_3x3'))

  14.      (self.feed('pool2_3x3_s2')
  15.           .conv(1, 1, 16, 1, 1, name='inception_3a_5x5_reduce')
  16.           .conv(5, 5, 32, 1, 1, name='inception_3a_5x5'))

  17.      (self.feed('pool2_3x3_s2')
  18.           .max_pool(3, 3, 1, 1, name='inception_3a_pool')
  19.           .conv(1, 1, 32, 1, 1, name='inception_3a_pool_proj'))

  20.      (self.feed('inception_3a_1x1',
  21.                 'inception_3a_3x3',
  22.                 'inception_3a_5x5',
  23.                 'inception_3a_pool_proj')
  24.           .concat(3, name='inception_3a_output')
  25.           .conv(1, 1, 128, 1, 1, name='inception_3b_1x1'))

  26.      (self.feed('inception_3a_output')
  27.           .conv(1, 1, 128, 1, 1, name='inception_3b_3x3_reduce')
  28.           .conv(3, 3, 192, 1, 1, name='inception_3b_3x3'))

  29.      (self.feed('inception_3a_output')
  30.           .conv(1, 1, 32, 1, 1, name='inception_3b_5x5_reduce')
  31.           .conv(5, 5, 96, 1, 1, name='inception_3b_5x5'))

  32.      (self.feed('inception_3a_output')
  33.           .max_pool(3, 3, 1, 1, name='inception_3b_pool')
  34.           .conv(1, 1, 64, 1, 1, name='inception_3b_pool_proj'))

  35.      (self.feed('inception_3b_1x1',
  36.                 'inception_3b_3x3',
  37.                 'inception_3b_5x5',
  38.                 'inception_3b_pool_proj')
  39.           .concat(3, name='inception_3b_output')
  40.           .max_pool(3, 3, 2, 2, name='pool3_3x3_s2')
  41.           .conv(1, 1, 192, 1, 1, name='inception_4a_1x1'))

  42.      (self.feed('pool3_3x3_s2')
  43.           .conv(1, 1, 96, 1, 1, name='inception_4a_3x3_reduce')
  44.           .conv(3, 3, 208, 1, 1, name='inception_4a_3x3'))

  45.      (self.feed('pool3_3x3_s2')
  46.           .conv(1, 1, 16, 1, 1, name='inception_4a_5x5_reduce')
  47.           .conv(5, 5, 48, 1, 1, name='inception_4a_5x5'))

  48.      (self.feed('pool3_3x3_s2')
  49.           .max_pool(3, 3, 1, 1, name='inception_4a_pool')
  50.           .conv(1, 1, 64, 1, 1, name='inception_4a_pool_proj'))

  51.      (self.feed('inception_4a_1x1',
  52.                 'inception_4a_3x3',
  53.                 'inception_4a_5x5',
  54.                 'inception_4a_pool_proj')
  55.           .concat(3, name='inception_4a_output')
  56.           .conv(1, 1, 160, 1, 1, name='inception_4b_1x1'))

  57.      (self.feed('inception_4a_output')
  58.           .conv(1, 1, 112, 1, 1, name='inception_4b_3x3_reduce')
  59.           .conv(3, 3, 224, 1, 1, name='inception_4b_3x3'))

  60.      (self.feed('inception_4a_output')
  61.           .conv(1, 1, 24, 1, 1, name='inception_4b_5x5_reduce')
  62.           .conv(5, 5, 64, 1, 1, name='inception_4b_5x5'))

  63.      (self.feed('inception_4a_output')
  64.           .max_pool(3, 3, 1, 1, name='inception_4b_pool')
  65.           .conv(1, 1, 64, 1, 1, name='inception_4b_pool_proj'))

  66.      (self.feed('inception_4b_1x1',
  67.                 'inception_4b_3x3',
  68.                 'inception_4b_5x5',
  69.                 'inception_4b_pool_proj')
  70.           .concat(3, name='inception_4b_output')
  71.           .conv(1, 1, 128, 1, 1, name='inception_4c_1x1'))

  72.      (self.feed('inception_4b_output')
  73.           .conv(1, 1, 128, 1, 1, name='inception_4c_3x3_reduce')
  74.           .conv(3, 3, 256, 1, 1, name='inception_4c_3x3'))

  75.      (self.feed('inception_4b_output')
  76.           .conv(1, 1, 24, 1, 1, name='inception_4c_5x5_reduce')
  77.           .conv(5, 5, 64, 1, 1, name='inception_4c_5x5'))

  78.      (self.feed('inception_4b_output')
  79.           .max_pool(3, 3, 1, 1, name='inception_4c_pool')
  80.           .conv(1, 1, 64, 1, 1, name='inception_4c_pool_proj'))

  81.      (self.feed('inception_4c_1x1',
  82.                 'inception_4c_3x3',
  83.                 'inception_4c_5x5',
  84.                 'inception_4c_pool_proj')
  85.           .concat(3, name='inception_4c_output')
  86.           .conv(1, 1, 112, 1, 1, name='inception_4d_1x1'))

  87.      (self.feed('inception_4c_output')
  88.           .conv(1, 1, 144, 1, 1, name='inception_4d_3x3_reduce')
  89.           .conv(3, 3, 288, 1, 1, name='inception_4d_3x3'))

  90.      (self.feed('inception_4c_output')
  91.           .conv(1, 1, 32, 1, 1, name='inception_4d_5x5_reduce')
  92.           .conv(5, 5, 64, 1, 1, name='inception_4d_5x5'))

  93.      (self.feed('inception_4c_output')
  94.           .max_pool(3, 3, 1, 1, name='inception_4d_pool')
  95.           .conv(1, 1, 64, 1, 1, name='inception_4d_pool_proj'))

  96.      (self.feed('inception_4d_1x1',
  97.                 'inception_4d_3x3',
  98.                 'inception_4d_5x5',
  99.                 'inception_4d_pool_proj')
  100.           .concat(3, name='inception_4d_output')
  101.           .conv(1, 1, 256, 1, 1, name='inception_4e_1x1'))

  102.      (self.feed('inception_4d_output')
  103.           .conv(1, 1, 160, 1, 1, name='inception_4e_3x3_reduce')
  104.           .conv(3, 3, 320, 1, 1, name='inception_4e_3x3'))

  105.      (self.feed('inception_4d_output')
  106.           .conv(1, 1, 32, 1, 1, name='inception_4e_5x5_reduce')
  107.           .conv(5, 5, 128, 1, 1, name='inception_4e_5x5'))

  108.      (self.feed('inception_4d_output')
  109.           .max_pool(3, 3, 1, 1, name='inception_4e_pool')
  110.           .conv(1, 1, 128, 1, 1, name='inception_4e_pool_proj'))

  111.      (self.feed('inception_4e_1x1',
  112.                 'inception_4e_3x3',
  113.                 'inception_4e_5x5',
  114.                 'inception_4e_pool_proj')
  115.           .concat(3, name='inception_4e_output')
  116.           .max_pool(3, 3, 2, 2, name='pool4_3x3_s2')
  117.           .conv(1, 1, 256, 1, 1, name='inception_5a_1x1'))

  118.      (self.feed('pool4_3x3_s2')
  119.           .conv(1, 1, 160, 1, 1, name='inception_5a_3x3_reduce')
  120.           .conv(3, 3, 320, 1, 1, name='inception_5a_3x3'))

  121.      (self.feed('pool4_3x3_s2')
  122.           .conv(1, 1, 32, 1, 1, name='inception_5a_5x5_reduce')
  123.           .conv(5, 5, 128, 1, 1, name='inception_5a_5x5'))

  124.      (self.feed('pool4_3x3_s2')
  125.           .max_pool(3, 3, 1, 1, name='inception_5a_pool')
  126.           .conv(1, 1, 128, 1, 1, name='inception_5a_pool_proj'))

  127.      (self.feed('inception_5a_1x1',
  128.                 'inception_5a_3x3',
  129.                 'inception_5a_5x5',
  130.                 'inception_5a_pool_proj')
  131.           .concat(3, name='inception_5a_output')
  132.           .conv(1, 1, 384, 1, 1, name='inception_5b_1x1'))

  133.      (self.feed('inception_5a_output')
  134.           .conv(1, 1, 192, 1, 1, name='inception_5b_3x3_reduce')
  135.           .conv(3, 3, 384, 1, 1, name='inception_5b_3x3'))

  136.      (self.feed('inception_5a_output')
  137.           .conv(1, 1, 48, 1, 1, name='inception_5b_5x5_reduce')
  138.           .conv(5, 5, 128, 1, 1, name='inception_5b_5x5'))

  139.      (self.feed('inception_5a_output')
  140.           .max_pool(3, 3, 1, 1, name='inception_5b_pool')
  141.           .conv(1, 1, 128, 1, 1, name='inception_5b_pool_proj'))

  142.      (self.feed('inception_5b_1x1',
  143.                 'inception_5b_3x3',
  144.                 'inception_5b_5x5',
  145.                 'inception_5b_pool_proj')
  146.           .concat(3, name='inception_5b_output')
  147.           .avg_pool(7, 7, 1, 1, padding='VALID', name='pool5_7x7_s1')
  148.           .fc(1000, relu=False, name='loss3_classifier')
  149.           .softmax(name='prob'))

   代码在GitHub - ethereon/caffe-tensorflow: Caffe models in TensorFlow中,作者封装了一些基本的操作,了解网络结构之后,构造GoogLeNet很容易。之后等到新公司之后,我会试着在tflearn的基础上写下GoogLeNet的网络代码。

 

除特别注明外,本站所有文章均为 赢咖4注册 原创,转载请注明出处来自机器学习进阶笔记之四 | 深入理解GoogLeNet

留言与评论(共有 0 条评论)
   
验证码:
[lianlun]1[/lianlun]