Exemplo n.º 1
0
import cv2
import numpy as np
import os
import sys
import glob

sys.path.append(os.path.join(os.getcwd(), 'lib'))
import create_mnist_jpg as im_creator
import basic_dnn as dnn
import tensorflow as tf

img_file_path = os.path.join(os.getcwd(), 'MnistImage/Train')

dataset = im_creator.img_to_data_set(img_file_path)

dnn.train(np.array(dataset, np.float32),
          im_creator.labels().astype(np.float32))
Exemplo n.º 2
0
def conv2d(x, W):
    # stride [1, x_movement, y_movement, 1]
    # Must have strides[0] = strides[3] = 1
    return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME')


def max_pool_2x2(x):
    # stride [1, x_movement, y_movement, 1]
    return tf.nn.max_pool(x,
                          ksize=[1, 2, 2, 1],
                          strides=[1, 2, 2, 1],
                          padding='SAME')


train_img_file_path = os.path.join(os.getcwd(), 'MnistImage/Train')
dataset = im_creator.img_to_data_set(train_img_file_path)
traning_lables = im_creator.train_labels()

input_shape = np.shape(dataset[0])
shape_size = input_shape[0] * input_shape[1] * input_shape[2]
dataset = np.reshape(dataset, [np.shape(dataset)[0], shape_size])
out_size = np.shape(traning_lables)[1]

test_img_file_path = os.path.join(os.getcwd(), 'MnistImage/Test')
test_dataset = im_creator.img_to_data_set(test_img_file_path)
input_shape = np.shape(test_dataset[0])
shape_size = input_shape[0] * input_shape[1] * input_shape[2]
test_dataset = np.reshape(test_dataset,
                          [np.shape(test_dataset)[0], shape_size])
test_labels = im_creator.test_labels()
Exemplo n.º 3
0
import numpy as np
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import sys
import glob
sys.path.append(os.path.join(os.getcwd(), 'lib'))
import create_mnist_jpg as im_creator
import basic_nn_batch as batch_nn
import cnn
import tensorflow as tf

train_x_file_path = os.path.join(os.getcwd(), 'image_generator_train/x_samll')
train_y_file_path = os.path.join(os.getcwd(), 'image_generator_train/y_small')
dataset = im_creator.img_to_data_set(train_x_file_path)
input_shape = np.shape(dataset[0])
shape_size = input_shape[0] * input_shape[1] * input_shape[2]
batch_size = np.shape(dataset)[0]
dataset = np.reshape(dataset, [batch_size, shape_size])

expected_output = im_creator.img_to_data_set(train_y_file_path)
expected_output_shape = np.shape(expected_output[0])
# expected_output_shape_size = expected_output_shape[0] * expected_output_shape[1] * expected_output_shape[2]
# expected_output = np.reshape(expected_output, [np.shape(expected_output)[0], expected_output_shape_size] )

sess = tf.Session()
cnn.train_generator(dataset[0:batch_size], expected_output[0:batch_size], sess,
                    [input_shape[0], input_shape[1]], expected_output_shape)