ramy  2017-12-04 08:11:32  机器学习 |   查看评论   

  后来发现了tflearn里面有一个alexnet来分类Oxford的例子,好开心,在基于tflearn对一些日常layer的封装,代码量只有不到50行,看了下内部layer的实现,挺不错的,写代码的时候可以多参考参考,代码地址:https://github.com/tflearn/tflearn/blob/master/examples/images/alexnet.py.

  1.  from __future__ import division, print_function, absolute_import

  2.  import tflearn
  3.  from tflearn.layers.core import input_data, dropout, fully_connected
  4.  from tflearn.layers.conv import conv_2d, max_pool_2d
  5.  from tflearn.layers.normalization import local_response_normalization
  6.  from tflearn.layers.estimator import regression

  7.  import tflearn.datasets.oxflower17 as oxflower17
  8.  X, Y = oxflower17.load_data(one_hot=True, resize_pics=(227, 227))

  9.  # Building 'AlexNet'
  10.  network = input_data(shape=[None, 227, 227, 3])
  11.  network = conv_2d(network, 96, 11, strides=4, activation='relu')
  12.  network = max_pool_2d(network, 3, strides=2)
  13.  network = local_response_normalization(network)
  14.  network = conv_2d(network, 256, 5, activation='relu')
  15.  network = max_pool_2d(network, 3, strides=2)
  16.  network = local_response_normalization(network)
  17.  network = conv_2d(network, 384, 3, activation='relu')
  18.  network = conv_2d(network, 384, 3, activation='relu')
  19.  network = conv_2d(network, 256, 3, activation='relu')
  20.  network = max_pool_2d(network, 3, strides=2)
  21.  network = local_response_normalization(network)
  22.  network = fully_connected(network, 4096, activation='tanh')
  23.  network = dropout(network, 0.5)
  24.  network = fully_connected(network, 4096, activation='tanh')
  25.  network = dropout(network, 0.5)
  26.  network = fully_connected(network, 17, activation='softmax')
  27.  network = regression(network, optimizer='momentum',
  28.                       loss='categorical_crossentropy',
  29.                       learning_rate=0.001)

  30.  # Training
  31.  model = tflearn.DNN(network, checkpoint_path='model_alexnet',
  32.                      max_checkpoints=1, tensorboard_verbose=2)
  33.  model.fit(X, Y, n_epoch=1000, validation_set=0.1, shuffle=True,
  34.            show_metric=True, batch_size=64, snapshot_step=200,
  35.            snapshot_epoch=False, run_id='alexnet_oxflowers17')

  使用tflearn版本的alexnet来做实验,从TensorBoard上得到的基本效果如下, alexnet graph 如下:

alexnet graph

alexnet graph

  
 

除特别注明外,本站所有文章均为 人工智能学习网 原创,转载请注明出处来自机器学习进阶笔记之三 | 深入理解Alexnet

留言与评论(共有 0 条评论)
   
验证码: