• 大小: 20.88MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-06-27
  • 语言: 其他
  • 标签: 图像识别  

资源简介

通过TensorFlow搭建卷积神经网络实现猫狗识别代码,训练和测试代码完整,下载之后可以直接运行测试打码,运行环境在Linux下,需要把代码中的路径修改为本机实际路径

资源截图

代码片段和文件信息

# =========================================================================
import tensorflow as tf


# =========================================================================

# images image batch 4D tensor tf.float32 [batch_size width height channels]
# logits float [batch_size n_classes]
def inference(images batch_size n_classes):
    # 
    # conv1
    # 
    with tf.variable_scope(‘conv1‘) as scope:
        weights = tf.Variable(tf.truncated_normal(shape=[3 3 3 64] stddev=1.0 dtype=tf.float32)
                              name=‘weights‘ dtype=tf.float32)

        biases = tf.Variable(tf.constant(value=0.1 dtype=tf.float32 shape=[64])
                             name=‘biases‘ dtype=tf.float32)

        conv = tf.nn.conv2d(images weights strides=[1 1 1 1] padding=‘SAME‘)
        pre_activation = tf.nn.bias_add(conv biases)
        conv1 = tf.nn.relu(pre_activation name=scope.name)

    # pooling1
    # 
    with tf.variable_scope(‘pooling1_lrn‘) as scope:
        pool1 = tf.nn.max_pool(conv1 ksize=[1 3 3 1] strides=[1 2 2 1] padding=‘SAME‘ name=‘pooling1‘)
        norm1 = tf.nn.lrn(pool1 depth_radius=4 bias=1.0 alpha=0.001 / 9.0 beta=0.75 name=‘norm1‘)

    # conv2
    with tf.variable_scope(‘conv2‘) as scope:
        weights = tf.Variable(tf.truncated_normal(shape=[3 3 64 16] stddev=0.1 dtype=tf.float32)
                              name=‘weights‘ dtype=tf.float32)

        biases = tf.Variable(tf.constant(value=0.1 dtype=tf.float32 shape=[16])
                             name=‘biases‘ dtype=tf.float32)

        conv = tf.nn.conv2d(norm1 weights strides=[1 1 1 1] padding=‘SAME‘)
        pre_activation = tf.nn.bias_add(conv biases)
        conv2 = tf.nn.relu(pre_activation name=‘conv2‘)

    # pooling2
    with tf.variable_scope(‘pooling2_lrn‘) as scope:
        norm2 = tf.nn.lrn(conv2 depth_radius=4 bias=1.0 alpha=0.001 / 9.0 beta=0.75 name=‘norm2‘)
        pool2 = tf.nn.max_pool(norm2 ksize=[1 3 3 1] strides=[1 1 1 1] padding=‘SAME‘ name=‘pooling2‘)

    # fc3
    with tf.variable_scope(‘local3‘) as scope:
        reshape = tf.reshape(pool2 shape=[batch_size -1])
        dim = reshape.get_shape()[1].value
        weights = tf.Variable(tf.truncated_normal(shape=[dim 128] stddev=0.005 dtype=tf.float32)
                              name=‘weights‘ dtype=tf.float32)

        biases = tf.Variable(tf.constant(value=0.1 dtype=tf.float32 shape=[128])
                             name=‘biases‘ dtype=tf.float32)

        local3 = tf.nn.relu(tf.matmul(reshape weights) + biases name=scope.name)

    # fc4
    with tf.variable_scope(‘local4‘) as scope:
        weights = tf.Variable(tf.truncated_normal(shape=[128 128] stddev=0.005 dtype=tf.float32)
                              name=‘weights‘ dtype=tf.float32)

        biases = tf.Variable(tf.constant(value=0.1 dtype=tf.float32 shape=[128])
                             name=‘biases‘ dtype=tf.float32)

  

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-08-17 15:04  CatVsDogRecong\
     文件       20436  2018-08-09 15:46  CatVsDogRecong\0.jpg
     文件       13170  2018-08-09 13:53  CatVsDogRecong\003.jpg
     目录           0  2018-08-17 15:04  CatVsDogRecong\log\
     文件      228222  2018-08-15 14:23  CatVsDogRecong\log\events.out.tfevents.1534313958.ubuntu
     文件        5005  2018-08-15 13:51  CatVsDogRecong\model.py
     文件        3800  2018-08-15 14:11  CatVsDogRecong\model.pyc
     目录           0  2018-08-17 15:04  CatVsDogRecong\modelsave\
     文件         173  2018-08-15 14:23  CatVsDogRecong\modelsave\checkpoint
     文件    25500900  2018-08-15 14:23  CatVsDogRecong\modelsave\model_ckpt-999.data-00000-of-00001
     文件        1250  2018-08-15 14:23  CatVsDogRecong\modelsave\model_ckpt-999.index
     文件      123779  2018-08-15 14:23  CatVsDogRecong\modelsave\model_ckpt-999.meta
     文件        1602  2018-08-17 15:01  CatVsDogRecong\test.py
     文件        3159  2018-08-17 12:54  CatVsDogRecong\train.py
     目录           0  2018-08-17 15:04  CatVsDogRecong\train_image\
     目录           0  2018-08-17 15:04  CatVsDogRecong\train_image\0\
     文件       20661  2018-08-09 13:45  CatVsDogRecong\train_image\0\000.jpg
     文件       20436  2018-08-09 13:45  CatVsDogRecong\train_image\0\001.jpg
     文件       20397  2018-08-09 13:45  CatVsDogRecong\train_image\0\002.jpg
     文件       18070  2018-08-09 13:46  CatVsDogRecong\train_image\0\003.jpg
     文件       14276  2018-08-09 13:46  CatVsDogRecong\train_image\0\004.jpg
     文件       16505  2018-08-09 13:46  CatVsDogRecong\train_image\0\005.jpg
     文件       16062  2018-08-09 13:46  CatVsDogRecong\train_image\0\006.jpg
     文件       12810  2018-08-09 13:47  CatVsDogRecong\train_image\0\007.jpg
     文件       22745  2018-08-09 13:47  CatVsDogRecong\train_image\0\008.jpg
     文件       16499  2018-08-09 13:47  CatVsDogRecong\train_image\0\009.jpg
     文件       20120  2018-08-09 13:47  CatVsDogRecong\train_image\0\010.jpg
     文件       17142  2018-08-09 13:47  CatVsDogRecong\train_image\0\011.jpg
     文件       16837  2018-08-09 13:48  CatVsDogRecong\train_image\0\012.jpg
     文件       19332  2018-08-09 13:48  CatVsDogRecong\train_image\0\013.jpg
     文件       24710  2018-08-09 13:49  CatVsDogRecong\train_image\0\014.jpg
............此处省略26个文件信息

评论

共有 条评论