mnist inception score


mnist inception score实例
资源截图
代码片段和文件信息
import gzip
import os

GPUID = 1
os.environ[“CUDA_VISIBLE_DEVICES“] = str(GPUID)

from scipy import ndimage
from six.moves import urllib
import numpy as np
import tensorflow as tf
import tensorflow.contrib.slim as slim
import math
import sys
import scipy.io


import pdb

print (“PACKAGES LOADED“)



def CNN(inputs _is_training=True):
    x   = tf.reshape(inputs [-1 28 28 1])
    batch_norm_params = {‘is_training‘: _is_training ‘decay‘: 0.9 ‘updates_collections‘: None}
    net = slim.conv2d(x 32 [5 5] padding=‘SAME‘
                      activation_fn       = tf.nn.relu
                      weights_initializer = tf.truncated_normal_initializer(stddev=0.01)
                      normalizer_fn       = slim.batch_norm
                      normalizer_params   = batch_norm_params
                      scope=‘conv1‘)
    net = slim.max_pool2d(net [2 2] scope=‘pool1‘)
    net = slim.conv2d(net 64 [5 5] scope=‘conv2‘)
    net = slim.max_pool2d(net [2 2] scope=‘pool2‘)
    net = slim.flatten(net scope=‘flatten3‘)
    net = slim.fully_connected(net 1024
                     activation_fn       = tf.nn.relu
                     weights_initializer = tf.truncated_normal_initializer(stddev=0.01)
                     normalizer_fn       = slim.batch_norm
                     normalizer_params   = batch_norm_params
                     scope=‘fc4‘)
    net = slim.dropout(net keep_prob=0.7 is_training=_is_training scope=‘dropout4‘)  
    out = slim.fully_connected(net 10 activation_fn=None normalizer_fn=None scope=‘fco‘)
    return out


# DATA URL
SOURCE_URL      = ‘http://yann.lecun.com/exdb/mnist/‘
DATA_DIRECTORY  = “data“
# PARAMETERS FOR MNIST
IMAGE_SIZE      = 28
NUM_CHANNELS    = 1
PIXEL_DEPTH     = 255
NUM_LABELS      = 10
VALIDATION_SIZE = 5000  # Size of the validation set.

# DOWNLOAD MNIST DATA IF NECESSARY
def maybe_download(filename):
    if not tf.gfile.Exists(DATA_DIRECTORY):
        tf.gfile.MakeDirs(DATA_DIRECTORY)
    filepath = os.path.join(DATA_DIRECTORY filename)
    if not tf.gfile.Exists(filepath):
        filepath _ = urllib.request.urlretrieve(SOURCE_URL + filename filepath)
        with tf.gfile.GFile(filepath) as f:
            size = f.size()
        print(‘Successfully downloaded‘ filename size ‘bytes.‘)
    return filepath

# EXTRACT IMAGES
def extract_data(filename num_images):
    with gzip.open(filename) as bytestream:
        bytestream.read(16)
        buf = bytestream.read(IMAGE_SIZE * IMAGE_SIZE * num_images * NUM_CHANNELS)
        data = np.frombuffer(buf dtype=np.uint8).astype(np.float32)
        data = (data - (PIXEL_DEPTH / 2.0)) / PIXEL_DEPTH # -0.5~0.5
        data = data.reshape(num_images IMAGE_SIZE IMAGE_SIZE NUM_CHANNELS)
        data = np.reshape(data [num_images -1])
    return data # [image index y x channels]

# EXTRACT LABELS
def extract_labels(filename num_images):
    with gzip.open(filename) as bytestream:
        bytestream.read(8)
        buf = by

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-11-24 02:18  MNIST_Inception_Score-master
     文件          17  2017-11-24 02:18  MNIST_Inception_Score-master.gitignore
     文件        1943  2017-11-24 02:18  MNIST_Inception_Score-masterREADME.md
     文件       12427  2017-11-24 02:18  MNIST_Inception_Score-mastericp_plot.pdf
     文件        8935  2017-11-24 02:18  MNIST_Inception_Score-mastermnist_cnn_icp_eval.py
     文件       10543  2017-11-24 02:18  MNIST_Inception_Score-mastermnist_cnn_train_slim.py
     文件         652  2017-11-24 02:18  MNIST_Inception_Score-mastermnist_icp_plot.py
     目录           0  2017-11-24 02:18  MNIST_Inception_Score-mastermodel
     文件          77  2017-11-24 02:18  MNIST_Inception_Score-mastermodelcheckpoint
     文件    39304068  2017-11-24 02:18  MNIST_Inception_Score-mastermodelmodel.ckpt.data-00000-of-00001
     文件        1131  2017-11-24 02:18  MNIST_Inception_Score-mastermodelmodel.ckpt.index
     文件      274516  2017-11-24 02:18  MNIST_Inception_Score-mastermodelmodel.ckpt.meta

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)