资源简介

猫狗图片的识别分类,通过一个Alexnet网络模型,对猫狗图片数据集进行训练,并保存模型

资源截图

代码片段和文件信息

import tensorflow as tf


def alexnet(x keep_prob num_classes):
    # conv1
    with tf.name_scope(‘conv1‘) as scope:
        kernel = tf.Variable(tf.truncated_normal([11 11 3 96] dtype=tf.float32
                                                 stddev=1e-1) name=‘weights‘)
        conv = tf.nn.conv2d(x kernel [1 4 4 1] padding=‘SAME‘)
        biases = tf.Variable(tf.constant(0.0 shape=[96] dtype=tf.float32)
                             trainable=True name=‘biases‘)
        bias = tf.nn.bias_add(conv biases)
        conv1 = tf.nn.relu(bias name=scope)

    # lrn1
    with tf.name_scope(‘lrn1‘) as scope:
        lrn1 = tf.nn.local_response_normalization(conv1
                                                  alpha=1e-4
                                                  beta=0.75
                                                  depth_radius=2
                                                  bias=2.0)

    # pool1
    with tf.name_scope(‘pool1‘) as scope:
        pool1 = tf.nn.max_pool(lrn1
                               ksize=[1 3 3 1]
                               strides=[1 2 2 1]
                               padding=‘VALID‘)

    # conv2
    with tf.name_scope(‘conv2‘) as scope:
        pool1_groups = tf.split(axis=3 value=pool1 num_or_size_splits=2)
        kernel = tf.Variable(tf.truncated_normal([5 5 48 256] dtype=tf.float32
                                                 stddev=1e-1) name=‘weights‘)
        kernel_groups = tf.split(axis=3 value=kernel num_or_size_splits=2)
        conv_up = tf.nn.conv2d(pool1_groups[0] kernel_groups[0] [1 1 1 1] padding=‘SAME‘)
        conv_down = tf.nn.conv2d(pool1_groups[1] kernel_groups[1] [1 1 1 1] padding=‘SAME‘)
        biases = tf.Variable(tf.constant(0.0 shape=[256] dtype=tf.float32)
                             trainable=True name=‘biases‘)
        biases_groups = tf.split(axis=0 value=biases num_or_size_splits=2)
        bias_up = tf.nn.bias_add(conv_up biases_groups[0])
        bias_down = tf.nn.bias_add(conv_down biases_groups[1])
        bias = tf.concat(axis=3 values=[bias_up bias_down])
        conv2 = tf.nn.relu(bias name=scope)

    # lrn2
    with tf.name_scope(‘lrn2‘) as scope:
        lrn2 = tf.nn.local_response_normalization(conv2
                                                  alpha=1e-4
                                                  beta=0.75
                                                  depth_radius=2
                                                  bias=2.0)

    # pool2
    with tf.name_scope(‘pool2‘) as scope:
        pool2 = tf.nn.max_pool(lrn2
                               ksize=[1 3 3 1]
                               strides=[1 2 2 1]
                               padding=‘VALID‘)

        # conv3
    with tf.name_scope(‘conv3‘) as scope:
        kernel = tf.Variable(tf.truncated_normal([3 3 256 384]
                 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-04-14 20:42  cats and dogs\
     目录           0  2019-04-14 20:42  cats and dogs\.idea\
     目录           0  2019-04-12 20:13  cats and dogs\.idea\inspectionProfiles\
     文件         243  2019-04-12 20:12  cats and dogs\.idea\misc.xml
     文件         276  2019-04-12 20:12  cats and dogs\.idea\modules.xml
     文件       16613  2019-04-13 21:03  cats and dogs\.idea\workspace.xml
     文件         459  2019-04-12 20:13  cats and dogs\.idea\猫狗大战.iml
     目录           0  2019-04-14 20:42  cats and dogs\__pycache__\
     文件        4107  2019-04-12 20:30  cats and dogs\__pycache__\alexnet.cpython-35.pyc
     文件        2213  2019-04-12 21:30  cats and dogs\__pycache__\datagenerator.cpython-35.pyc
     文件        7712  2019-04-12 20:15  cats and dogs\alexnet.py
     文件        2190  2019-04-12 21:16  cats and dogs\datagenerator.py
     文件        8543  2019-04-12 22:21  cats and dogs\main_alexnet.py
     文件        1151  2019-04-12 21:03  cats and dogs\rename_file.py

评论

共有 条评论