コード例 #1
0
    mean, variance = tf.nn.moments(x, axes=[0, 1, 2])
    return tf.nn.batch_normalization(x, mean, variance, None, None, 0.0001)

def fc_batch_normalization(x):
    mean, variance = tf.nn.moments(x, axes=[0])
    return tf.nn.batch_normalization(x, mean, variance, None, None, 0.0001)


list_ = []
for line in open("/mnt/ds3lab/tf_imagenet/label.txt"):
    list_.append(['a', line.strip('\n')])
classes = np.array(list_)
print len(classes)


train_dataset, val_dataset, test_dataset = create_datasets(classes[:, 1], num_samples=NUM_IMAGES, val_fraction=0.1,
                                                           test_fraction=0.1)
num_classes = len(classes)
print num_classes
#print ALL_IMAGES_NUM
# can change the device here
with tf.device('/gpu:0'):
# Placeholders
    x = tf.placeholder(tf.float32, shape=[None, input_data.IMAGE_WIDTH * input_data.IMAGE_HEIGHT, 3])
    y_ = tf.placeholder(tf.float32, shape=[None, num_classes])
    keep_prob = tf.placeholder(tf.float32)

    x_reshaped = tf.reshape(x, [-1, input_data.IMAGE_WIDTH, input_data.IMAGE_HEIGHT, 3])  
    #First convolutional layer, (224, 224, 3) to (56, 56, 96)    
    W_conv1 = weight_variable([11, 11, 3, 96])    
    b_conv1 = bias_variable([96]) # convert it to (56,56,96) now     
    h_conv1 = tf.nn.relu(conv2d(x_reshaped, W_conv1, [1, 4, 4, 1]) + b_conv1)   
コード例 #2
0
def max_pool_2x2(x):
    return tf.nn.max_pool(x, ksize=[1, 2, 2, 1],
                          strides=[1, 2, 2, 1], padding='SAME')


def conv_batch_normalization(x):
    mean, variance = tf.nn.moments(x, axes=[0, 1, 2])
    return tf.nn.batch_normalization(x, mean, variance, None, None, 0.0001)


def fc_batch_normalization(x):
    mean, variance = tf.nn.moments(x, axes=[0])
    return tf.nn.batch_normalization(x, mean, variance, None, None, 0.0001)


train_dataset, val_dataset, test_dataset = create_datasets(classes[:, 1], num_samples=NUM_IMAGES, val_fraction=0.05,
                                                           test_fraction=0.05)
num_classes = len(classes)

# Placeholders
x = tf.placeholder(tf.float32, shape=[None, input_data.IMAGE_WIDTH * input_data.IMAGE_HEIGHT, 3])
y_ = tf.placeholder(tf.float32, shape=[None, num_classes])

x_reshaped = tf.reshape(x, [-1, input_data.IMAGE_WIDTH, input_data.IMAGE_HEIGHT, 3])

# First convolutional layer, (224, 224, 3) to (56, 56, 48)
W_conv1 = weight_variable([11, 11, 3, 48])
b_conv1 = bias_variable([48])

h_conv1 = tf.nn.relu(conv2d(x_reshaped, W_conv1, [1, 4, 4, 1]) + b_conv1)

# Second convolutional layer, (56, 56, 48) to (28, 28, 128)