<commit_before>#!/usr/bin/python
# -*- coding:utf-8 -*-

import tensorflow as tf
from tools import visualize


NUMBER_CLASSES = 10
IMAGE_WIDTH = 32
IMAGE_HEIGHT = 32
IMAGE_CHANNELS = 3
DATASET_PATH = '/home/workspace/cifar10/pythonver'
LEARNING_RATE = 0.001
MOMENTUM = 0.9
batch_size = 128
epoches = 5
KEEP_PROB = 0.6
LOG_DIR = 'Log--' + visualize.get_time()


def convolution(data, kernel, strides, name, bias, padding='SAME'):
    with tf.name_scope(name):
        conv = tf.nn.conv2d(input=data, filter=kernel, strides=[1, strides, strides, 1], padding=padding, name=name)
        with tf.name_scope(name+'_relu'):
            conv = tf.nn.bias_add(conv, bias)
            relu = tf.nn.relu(conv, name=name+'_relu')
            return relu


def pooling(data, ksize, strides, name, padding='SAME'):
    with tf.name_scope(name):
        return tf.nn.max_pool(value=data, ksize=[1, ksize, ksize, 1], strides=[1, strides, strides, 1],
                              padding=padding, name=name)


def fullconnection(data, weights, biases, name, relu_bias, relu=False):
    with tf.name_scope(name):
        fc = tf.nn.bias_add(tf.matmul(data, weights), biases, name=name)
        if not relu:
            return fc
        with tf.name_scope(name+'_relu'):
            fc = tf.nn.bias_add(fc, relu_bias)
            relu = tf.nn.relu(fc, name=(name+'_relu'))
            return relu


def model(input, model_param):
    conv1 = convolution(data=input, kernel=model_param['conv1_kernel'], strides=model_param['conv1_strides'], bias=model_param['conv1_biases'], name=model_param['conv1_name'], padding=model_param['conv1_padding'])
    conv2 = convolution(data=conv1, kernel=model_param['conv2_kernel'], strides=model_param['conv2_strides'], bias=model_param['conv2_biases'], name=model_param['conv2_name'], padding=model_param['conv2_padding'])

    pool1 = pooling(data=conv2, ksize=model_param['pool1_ksize'], strides=model_param['pool1_strides'], name=model_param['pool1_name'], padding=model_param['pool1_padding'])

    conv3 = convolution(data=pool1, kernel=model_param['conv3_kernel'], strides=model_param['conv3_strides'], bias=model_param['conv3_biases'], name=model_param['conv3_name'], padding=model_param['conv3_padding'])
    conv4 = convolution(data=conv3, kernel=model_param['conv4_kernel'], strides=model_param['conv4_strides'], bias=model_param['conv4_biases'], name=model_param['conv4_name'], padding=model_param['conv4_padding'])

    pool2 = pooling(data=conv4, ksize=model_param['pool2_ksize'], strides=model_param['pool2_strides'], name=model_param['pool2_name'], padding=model_param['pool2_padding'])

    conv5 = convolution(data=pool2, kernel=model_param['conv5_kernel'], strides=model_param['conv5_strides'], bias=model_param['conv5_biases'], name=model_param['conv5_name'], padding=model_param['conv5_padding'])
    conv6 = convolution(data=conv5, kernel=model_param['conv6_kernel'], strides=model_param['conv6_strides'], bias=model_param['conv6_biases'], name=model_param['conv6_name'], padding=model_param['conv6_padding'])
    conv7 = convolution(data=conv6, kernel=model_param['conv7_kernel'], strides=model_param['conv7_strides'], bias=model_param['conv7_biases'], name=model_param['conv7_name'], padding=model_param['conv7_padding'])

    pool3 = pooling(data=conv7, ksize=model_param['pool3_ksize'], strides=model_param['pool3_strides'], name=model_param['pool3_name'], padding=model_param['pool3_padding'])

    conv8 = convolution(data=pool3, kernel=model_param['conv8_kernel'], strides=model_param['conv8_strides'], bias=model_param['conv8_biases'], name=model_param['conv8_name'], padding=model_param['conv8_padding'])
    conv9 = convolution(data=conv8, kernel=model_param['conv9_kernel'], strides=model_param['conv9_strides'], bias=model_param['conv9_biases'], name=model_param['conv9_name'], padding=model_param['conv9_padding'])
    conv10 = convolution(data=conv9, kernel=model_param['conv10_kernel'], strides=model_param['conv10_strides'], bias=model_param['conv10_biases'], name=model_param['conv10_name'], padding=model_param['conv10_padding'])

    pool4 = pooling(data=conv10, ksize=model_param['pool4_ksize'], strides=model_param['pool4_strides'], name=model_param['pool4_name'], padding=model_param['pool4_padding'])

    conv11 = convolution(data=pool4, kernel=model_param['conv11_kernel'], strides=model_param['conv11_strides'], bias=model_param['conv11_biases'], name=model_param['conv11_name'], padding=model_param['conv11_padding'])
    conv12 = convolution(data=conv11, kernel=model_param['conv12_kernel'], strides=model_param['conv12_strides'], bias=model_param['conv12_biases'], name=model_param['conv12_name'], padding=model_param['conv12_padding'])
    conv13 = convolution(data=conv12, kernel=model_param['conv13_kernel'], strides=model_param['conv13_strides'], bias=model_param['conv13_biases'], name=model_param['conv13_name'], padding=model_param['conv13_padding'])

    pool5 = pooling(data=conv13, ksize=model_param['pool5_ksize'], strides=model_param['pool5_strides'], name=model_param['pool5_name'], padding=model_param['pool5_padding'])
    pool5 = tf.reshape(pool5, shape=[-1, model_param['fc1_weights'].get_shape()[0].value])

    fc1 = fullconnection(data=pool5, weights=model_param['fc1_weights'], biases=model_param['fc1_biases'], relu_bias=model_param['fc1_relu_biases'], name=model_param['fc1_name'], relu=model_param['fc1_relu'])
    fc2 = fullconnection(data=fc1, weights=model_param['fc2_weights'], biases=model_param['fc2_biases'], relu_bias=model_param['fc2_relu_biases'], name=model_param['fc2_name'], relu=model_param['fc2_relu'])
    fc3 = fullconnection(data=fc2, weights=model_param['fc3_weights'], biases=model_param['fc3_biases'], relu_bias=model_param['fc3_relu_biases'], name=model_param['fc3_name'])
    drop = tf.nn.dropout(fc3, keep_prob=KEEP_PROB)
    return drop


def init_param():
    model_param = {
        'conv1_kernel': tf.Variable(tf.truncated_normal(shape=[3, 3, 3, 64], stddev=1e-2, dtype=tf.float32)), 'conv1_strides': 1, 'conv1_biases': tf.Variable(tf.constant(0.0, shape=[64], dtype=tf.float32)), 'conv1_name': 'conv1', 'conv1_padding': 'SAME',
        'conv2_kernel': tf.Variable(tf.truncated_normal(shape=[3, 3, 64, 64], stddev=1e-2, dtype=tf.float32)), 'conv2_strides': 1, 'conv2_biases': tf.Variable(tf.constant(0.0, shape=[64], dtype=tf.float32)), 'conv2_name': 'conv2', 'conv2_padding': 'SAME',
        'pool1_ksize': 2, 'pool1_strides': 2, 'pool1_name': 'pool1', 'pool1_padding': 'SAME',
        'conv3_kernel': tf.Variable(tf.truncated_normal(shape=[3, 3, 64, 128], stddev=1e-2, dtype=tf.float32)), 'conv3_strides': 1, 'conv3_biases': tf.Variable(tf.constant(0.0, shape=[128], dtype=tf.float32)), 'conv3_name': 'conv3', 'conv3_padding': 'SAME',
        'conv4_kernel': tf.Variable(tf.truncated_normal(shape=[3, 3, 128, 128], stddev=1e-2, dtype=tf.float32)), 'conv4_strides': 1, 'conv4_biases': tf.Variable(tf.constant(0.0, shape=[128], dtype=tf.float32)), 'conv4_name': 'conv4', 'conv4_padding': 'SAME',
        'pool2_ksize': 2, 'pool2_strides': 2, 'pool2_name': 'pool2', 'pool2_padding': 'SAME',<commit_msg>vgg tensorflow version with tensorboard<commit_after>#!/usr/bin/python
# -*- coding:utf-8 -*-

import tensorflow as tf
from tools import visualize


NUMBER_CLASSES = 10
IMAGE_WIDTH = 32
IMAGE_HEIGHT = 32
IMAGE_CHANNELS = 3
DATASET_PATH = '/home/workspace/cifar10/pythonver'
LEARNING_RATE = 0.001
MOMENTUM = 0.9
batch_size = 128
epoches = 5
KEEP_PROB = 0.6
LOG_DIR = 'Log--' + visualize.get_time()


def convolution(data, kernel, strides, name, bias, padding='SAME'):
    with tf.name_scope(name):
        conv = tf.nn.conv2d(input=data, filter=kernel, strides=[1, strides, strides, 1], padding=padding, name=name)
        with tf.name_scope(name+'_relu'):
            conv = tf.nn.bias_add(conv, bias)
            relu = tf.nn.relu(conv, name=name+'_relu')
            return relu


def pooling(data, ksize, strides, name, padding='SAME'):
    with tf.name_scope(name):
        return tf.nn.max_pool(value=data, ksize=[1, ksize, ksize, 1], strides=[1, strides, strides, 1],
                              padding=padding, name=name)


def fullconnection(data, weights, biases, name, relu_bias, relu=False):
    with tf.name_scope(name):
        fc = tf.nn.bias_add(tf.matmul(data, weights), biases, name=name)
        if not relu:
            return fc
        with tf.name_scope(name+'_relu'):
            fc = tf.nn.bias_add(fc, relu_bias)
            relu = tf.nn.relu(fc, name=(name+'_relu'))
            return relu


def model(input, model_param):
    conv1 = convolution(data=input, kernel=model_param['conv1_kernel'], strides=model_param['conv1_strides'], bias=model_param['conv1_biases'], name=model_param['conv1_name'], padding=model_param['conv1_padding'])
    conv2 = convolution(data=conv1, kernel=model_param['conv2_kernel'], strides=model_param['conv2_strides'], bias=model_param['conv2_biases'], name=model_param['conv2_name'], padding=model_param['conv2_padding'])

    pool1 = pooling(data=conv2, ksize=model_param['pool1_ksize'], strides=model_param['pool1_strides'], name=model_param['pool1_name'], padding=model_param['pool1_padding'])

    conv3 = convolution(data=pool1, kernel=model_param['conv3_kernel'], strides=model_param['conv3_strides'], bias=model_param['conv3_biases'], name=model_param['conv3_name'], padding=model_param['conv3_padding'])
    conv4 = convolution(data=conv3, kernel=model_param['conv4_kernel'], strides=model_param['conv4_strides'], bias=model_param['conv4_biases'], name=model_param['conv4_name'], padding=model_param['conv4_padding'])

    pool2 = pooling(data=conv4, ksize=model_param['pool2_ksize'], strides=model_param['pool2_strides'], name=model_param['pool2_name'], padding=model_param['pool2_padding'])

    conv5 = convolution(data=pool2, kernel=model_param['conv5_kernel'], strides=model_param['conv5_strides'], bias=model_param['conv5_biases'], name=model_param['conv5_name'], padding=model_param['conv5_padding'])
    conv6 = convolution(data=conv5, kernel=model_param['conv6_kernel'], strides=model_param['conv6_strides'], bias=model_param['conv6_biases'], name=model_param['conv6_name'], padding=model_param['conv6_padding'])
    conv7 = convolution(data=conv6, kernel=model_param['conv7_kernel'], strides=model_param['conv7_strides'], bias=model_param['conv7_biases'], name=model_param['conv7_name'], padding=model_param['conv7_padding'])

    pool3 = pooling(data=conv7, ksize=model_param['pool3_ksize'], strides=model_param['pool3_strides'], name=model_param['pool3_name'], padding=model_param['pool3_padding'])

    conv8 = convolution(data=pool3, kernel=model_param['conv8_kernel'], strides=model_param['conv8_strides'], bias=model_param['conv8_biases'], name=model_param['conv8_name'], padding=model_param['conv8_padding'])
    conv9 = convolution(data=conv8, kernel=model_param['conv9_kernel'], strides=model_param['conv9_strides'], bias=model_param['conv9_biases'], name=model_param['conv9_name'], padding=model_param['conv9_padding'])
    conv10 = convolution(data=conv9, kernel=model_param['conv10_kernel'], strides=model_param['conv10_strides'], bias=model_param['conv10_biases'], name=model_param['conv10_name'], padding=model_param['conv10_padding'])

    pool4 = pooling(data=conv10, ksize=model_param['pool4_ksize'], strides=model_param['pool4_strides'], name=model_param['pool4_name'], padding=model_param['pool4_padding'])

    conv11 = convolution(data=pool4, kernel=model_param['conv11_kernel'], strides=model_param['conv11_strides'], bias=model_param['conv11_biases'], name=model_param['conv11_name'], padding=model_param['conv11_padding'])
    conv12 = convolution(data=conv11, kernel=model_param['conv12_kernel'], strides=model_param['conv12_strides'], bias=model_param['conv12_biases'], name=model_param['conv12_name'], padding=model_param['conv12_padding'])
    conv13 = convolution(data=conv12, kernel=model_param['conv13_kernel'], strides=model_param['conv13_strides'], bias=model_param['conv13_biases'], name=model_param['conv13_name'], padding=model_param['conv13_padding'])

    pool5 = pooling(data=conv13, ksize=model_param['pool5_ksize'], strides=model_param['pool5_strides'], name=model_param['pool5_name'], padding=model_param['pool5_padding'])
    pool5 = tf.reshape(pool5, shape=[-1, model_param['fc1_weights'].get_shape()[0].value])

    fc1 = fullconnection(data=pool5, weights=model_param['fc1_weights'], biases=model_param['fc1_biases'], relu_bias=model_param['fc1_relu_biases'], name=model_param['fc1_name'], relu=model_param['fc1_relu'])
    fc2 = fullconnection(data=fc1, weights=model_param['fc2_weights'], biases=model_param['fc2_biases'], relu_bias=model_param['fc2_relu_biases'], name=model_param['fc2_name'], relu=model_param['fc2_relu'])
    drop = tf.nn.dropout(fc2, keep_prob=KEEP_PROB)
    fc3 = fullconnection(data=drop, weights=model_param['fc3_weights'], biases=model_param['fc3_biases'], relu_bias=model_param['fc3_relu_biases'], name=model_param['fc3_name'])
    return fc3


def init_param():
    model_param = {
        'conv1_kernel': tf.Variable(tf.truncated_normal(shape=[3, 3, 3, 64], stddev=1e-2, dtype=tf.float32)), 'conv1_strides': 1, 'conv1_biases': tf.Variable(tf.constant(0.0, shape=[64], dtype=tf.float32)), 'conv1_name': 'conv1', 'conv1_padding': 'SAME',
        'conv2_kernel': tf.Variable(tf.truncated_normal(shape=[3, 3, 64, 64], stddev=1e-2, dtype=tf.float32)), 'conv2_strides': 1, 'conv2_biases': tf.Variable(tf.constant(0.0, shape=[64], dtype=tf.float32)), 'conv2_name': 'conv2', 'conv2_padding': 'SAME',
        'pool1_ksize': 2, 'pool1_strides': 2, 'pool1_name': 'pool1', 'pool1_padding': 'SAME',
        'conv3_kernel': tf.Variable(tf.truncated_normal(shape=[3, 3, 64, 128], stddev=1e-2, dtype=tf.float32)), 'conv3_strides': 1, 'conv3_biases': tf.Variable(tf.constant(0.0, shape=[128], dtype=tf.float32)), 'conv3_name': 'conv3', 'conv3_padding': 'SAME',
        'conv4_kernel': tf.Variable(tf.truncated_normal(shape=[3, 3, 128, 128], stddev=1e-2, dtype=tf.float32)), 'conv4_strides': 1, 'conv4_biases': tf.Variable(tf.constant(0.0, shape=[128], dtype=tf.float32)), 'conv4_name': 'conv4', 'conv4_padding': 'SAME',
        'pool2_ksize': 2, 'pool2_strides': 2, 'pool2_name': 'pool2', 'pool2_padding': 'SAME',
{'fraction_non_alphanumeric': 0.16367713004484305, 'fraction_numerical': 0.04386210762331839, 'mean_word_length': 7.718998167379352, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2946397', 'n_tokens_mistral': 5301, 'n_tokens_neox': 4956, 'n_words': 703}