slim_usage.py 695 B

123456789101112131415161718
  1. # -*- coding:utf-8 -*-
  2. import tensorflow as tf
  3. import tensorflow.contrib.slim as slim
  4. import numpy as np
  5. from tensorflow.examples.tutorials.mnist import input_data
  6. def lenet5(inputs):
  7. inputs = tf.reshape(inputs, [-1, 28, 28, 1])
  8. net = slim.conv2d(inputs, 32, [5, 5], padding='SAME', scope='layer1-conv')
  9. net = slim.max_pool2d(net, 2, stride=2, scope='layer2-max-pool')
  10. net = slim.conv2d(net, 64, [5, 5], padding='SAME', scope='layer3-conv')
  11. net = slim.max_pool2d(net, 2, scope='layer4-max-pool')
  12. net = slim.flatten(net, scope='flatten')
  13. net = slim.fully_connected(net, 500, scope='layer5-fc')
  14. net = slim.fully_connected(net, 10, scope='output')
  15. return net