예제 #1
0
def init_conv(use_subset=False):
    "Dimensionalities of the filters (number of filters, k_i), d is set from X"
    f_1_dim = [20, 5]
    f_2_dim = [20, 3]
    f_dim = [f_1_dim, f_2_dim]

    "The variance to use when initializing filters/weights if not Xavier"
    sig_1 = 0.01
    sig_2 = 0.01
    sig_3 = 0.01
    sigmas = [sig_1, sig_2, sig_3]

    "Dim of X (d, n_len), and number of classes K"
    X_dim = [55, 19]
    K = 18

    conv = conv_net.conv_net(f_dim, X_dim, K, sigmas)

    "Loading the data set"
    df = pd.read_pickle('Datasets/X_data.pkl')
    char_to_ind = df[0][3]

    if (use_subset):
        subset_size = 1000
        X = np.array(df[0][0][:, :subset_size])
        Y = np.array(df[0][1][:, :subset_size])
        y = np.array(df[0][2][:subset_size])
    else:
        X = np.array(df[0][0])
        Y = np.array(df[0][1])
        y = np.array(df[0][2])

    return conv, X, Y, y, char_to_ind
예제 #2
0
파일: solver.py 프로젝트: izzrak/numpy_cnn
 def __init__(self):
     # config
     self.lr = 1e-4
     self.weight_decay = 0.0004
     self.batch_size = 50
     self.model = conv_net([self.batch_size, 28, 28, 1])  #MNIST input
     self.max_epoch = 1
     self.param_path = 'param.npy'
예제 #3
0
    def __init__(self, path):
        self.model = conv_net([1, 28, 28, 1])
        # load_param
        param_dict = np.load(path, encoding='bytes').item()
        conv1_param = param_dict['conv1']
        conv2_param = param_dict['conv2']
        fc_param = param_dict['fc']

        # fill weights
        self.model.conv1.weights = conv1_param['weights']
        self.model.conv1.bias = conv1_param['bias']
        self.model.conv2.weights = conv2_param['weights']
        self.model.conv2.bias = conv2_param['bias']
        self.model.fc.weights = fc_param['weights']
        self.model.fc.bias = fc_param['bias']
예제 #4
0
def test(test_file):
    image_arr = get_one_image(test_file)

    with tf.Graph().as_default():
        image = tf.cast(image_arr, tf.float32)
        image = tf.image.per_image_standardization(image)
        image = tf.reshape(image,[1,32,32,3])
        p = conv_net.conv_net(image,1)
        logits = tf.nn.softmax(p)
        x = tf.placeholder(tf.float32, shape=[32,32,3])
        saver = tf.train.Saver()
        with tf.Session() as sess:
            ckpt = tf.train.get_checkpoint_state('./model/')
            if ckpt and ckpt.model_checkpoint_path:
                #global_step = ckpt.model_checkpoint_path.split('/')[-1].split[-1]
                saver.restore(sess, ckpt.model_checkpoint_path)
                print('Loading success')
            else:
                print('No checkpoint')
            prediction =sess.run(logits, feed_dict={x: image_arr})
            max_index = np.argmax(prediction)
            print(prediction,max_index)
    return max_index
예제 #5
0
import tensorflow as tf
import conv_net as cv
"""
test = tf.keras.datasets.fashion_mnist

(train_X, train_Y), (test_X, test_Y) = test.load_data()

print(train_X.shape, train_Y.shape)
print(train_X[0])
"""

test = cv.conv_net(150)
test.neural_network_layer.summary()
예제 #6
0
    Gs[2] = G

    return Gs


def grad_check(conv):
    df = pd.read_pickle('Datasets/X_data.pkl')

    X = df[0][0]
    Y = df[0][1]

    check_grad(conv, X, Y, check_size=10)


f_1_dim = [20, 5]
f_2_dim = [20, 3]

sig_1 = 0.01
sig_2 = 0.01
sig_3 = 0.01

sigmas = [sig_1, sig_2, sig_3]

f_dim = [f_1_dim, f_2_dim]
X_dim = [55, 19]
K = 18

conv = conv.conv_net(f_dim, X_dim, K, sigmas)

grad_check(conv)
예제 #7
0
    config["mini_batch_size"] = 32
    config["pickle_file_location"] = config['opath']+'model.zip'
    config["output_images_location"] = config['opath'] + 'figs/'
    return config

def get_image():
    im = imread("boat.jpg")
    im = np.swapaxes(im,1,2)
    im = np.swapaxes(im,0,1)
    im = im[np.newaxis,:,:,:]
    print(im.shape)
    im = im.astype('float32')
    return im

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print "Arguments needs either be q1 or q2"
        exit(0)
    config = get_config()
    o_conv_net = conv_net(config)
    if sys.argv[1] == "q1":
        o_conv_net.train()
    elif sys.argv[1] == "q2":
        o_conv_net.q2(get_image())
    else:
        print "Arguments can either be q1 or q2"
        exit(0)



예제 #8
0
    config["ntest"] = 10000  # max is 10000
    config["mini_batch_size"] = 32
    config["pickle_file_location"] = config['opath'] + 'model.zip'
    config["output_images_location"] = config['opath'] + 'figs/'
    return config


def get_image():
    im = imread("boat.jpg")
    im = np.swapaxes(im, 1, 2)
    im = np.swapaxes(im, 0, 1)
    im = im[np.newaxis, :, :, :]
    print(im.shape)
    im = im.astype('float32')
    return im


if __name__ == "__main__":
    if len(sys.argv) < 2:
        print "Arguments needs either be q1 or q2"
        exit(0)
    config = get_config()
    o_conv_net = conv_net(config)
    if sys.argv[1] == "q1":
        o_conv_net.train()
    elif sys.argv[1] == "q2":
        o_conv_net.q2(get_image())
    else:
        print "Arguments can either be q1 or q2"
        exit(0)