Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- try:
- from scipy import misc
- except ImportError:
- !pip install scipy
- from scipy import misc
- #train
- import tensorflow as tf
- import numpy as np
- import matplotlib.pyplot as plt
- try:
- from scipy import misc
- except ImportError:
- !pip install scipy
- from scipy import misc
- training_size = 265
- img_size = 400*400
- training_data = np.empty(shape=(training_size, 400*400))
- import glob
- i = 0
- for filename in glob.glob('D:/TensorPalms/Train/*.jpg'):
- image = misc.imread(filename)
- print(image.shape)
- training_data[i] = image.reshape(-1)
- i+=1
- #label
- a= [0,0,0,0,0,
- 1,1,1,1,1,
- 2,2,2,2,2,
- 3,3,3,3,3,
- 4,4,4,4,4,
- 5,5,5,5,5,
- 6,6,6,6,6,
- 7,7,7,7,7,
- 8,8,8,8,8,
- 9,9,9,9,9,
- 10,10,10,10,10,
- 11,11,11,11,11,
- 12,12,12,12,12,
- 13,13,13,13,13,
- 14,14,14,14,14,
- 15,15,15,15,15,
- 16,16,16,16,16,
- 17,17,17,17,17,
- 18,18,18,18,18,
- 19,19,19,19,19,
- 20,20,20,20,20,
- 21,21,21,21,21,
- 22,22,22,22,22,
- 23,23,23,23,23,
- 24,24,24,24,24,
- 25,25,25,25,25,
- 26,26,26,26,26,
- 27,27,27,27,27,
- 28,28,28,28,28,
- 29,29,29,29,29,
- 30,30,30,30,30,
- 31,31,31,31,31,
- 32,32,32,32,32,
- 33,33,33,33,33,
- 34,34,34,34,34,
- 35,35,35,35,35,
- 36,36,36,36,36,
- 37,37,37,37,37,
- 38,38,38,38,38,
- 39,39,39,39,39,
- 40,40,40,40,40,
- 41,41,41,41,41,
- 42,42,42,42,42,
- 43,43,43,43,43,
- 44,44,44,44,44,
- 45,45,45,45,45,
- 46,46,46,46,46,
- 47,47,47,47,47,
- 48,48,48,48,48,
- 49,49,49,49,49,
- 50,50,50,50,50,
- 51,51,51,51,51,
- 52,52,52,52,52,]
- b = tf.one_hot(a,53)
- sess = tf.Session()
- sess.run(b)
- print(b.shape)
- #test
- import tensorflow as tf
- test_size = 159
- img_size = 400*400
- test_images = np.empty(shape=(test_size,400*400))
- import glob
- i = 0
- for filename in glob.glob('D:/TensorPalms/Test*.jpg'):
- image = misc.imread(filename)
- test_images[i] = image
- i+=1
- print(test_images[0].shape)
- c= [0,0,0,
- 1,1,1,
- 2,2,2,
- 3,3,3,
- 4,4,4,
- 5,5,5,
- 6,6,6,
- 7,7,7,
- 8,8,8,
- 9,9,9,
- 10,10,10,
- 11,11,11,
- 12,12,12,
- 13,13,13,
- 14,14,14,
- 15,15,15,
- 16,16,16,
- 17,17,17,
- 18,18,18,
- 19,19,19,
- 20,20,20,
- 21,21,21,
- 22,22,22,
- 23,23,23,
- 24,24,24,
- 25,25,25,
- 26,26,26,
- 27,27,27,
- 28,28,28,
- 29,29,29,
- 30,30,30,
- 31,31,31,
- 32,32,32,
- 33,33,33,
- 34,34,34,
- 35,35,35,
- 36,36,36,
- 37,37,37,
- 38,38,38,
- 39,39,39,
- 40,40,40,
- 41,41,41,
- 42,42,42,
- 43,43,43,
- 44,44,44,
- 45,45,45,
- 46,46,46,
- 47,47,47,
- 48,48,48,
- 49,49,49,
- 50,50,50,
- 51,51,51,
- 52,52,52]
- test_labels = tf.one_hot(c,53)
- sess = tf.Session()
- sess.run(test_labels)
- import tensorflow as tf
- tf.reset_default_graph()
- from __future__ import division, print_function, absolute_import
- import tflearn
- from tflearn.layers.core import input_data, dropout, fully_connected
- from tflearn.layers.conv import conv_2d, max_pool_2d
- from tflearn.layers.normalization import local_response_normalization
- from tflearn.layers.estimator import regression
- network = input_data(shape=[None, 400, 400,3])
- network = conv_2d(network, 96, 11, strides=4, activation='relu')
- network = max_pool_2d(network, 3, strides=2)
- network = local_response_normalization(network)
- network = conv_2d(network, 256, 5, activation='relu')
- network = max_pool_2d(network, 3, strides=2)
- network = local_response_normalization(network)
- network = conv_2d(network, 384, 3, activation='relu')
- network = conv_2d(network, 384, 3, activation='relu')
- network = conv_2d(network, 256, 3, activation='relu')
- network = max_pool_2d(network, 3, strides=2)
- network = local_response_normalization(network)
- network = fully_connected(network, 4096, activation='tanh')
- network = dropout(network, 0.5)
- network = fully_connected(network, 4096, activation='tanh')
- network = dropout(network, 0.5)
- network = fully_connected(network, 53, activation='softmax')
- network = regression(network, optimizer='momentum',
- loss='categorical_crossentropy',
- learning_rate=0.001)
- model = tflearn.DNN(network, checkpoint_path='model_alexnet',
- max_checkpoints=1, tensorboard_verbose=2)
- model.fit(training_data, b, n_epoch=1000, validation_set=(test_images, test_labels),
- shuffle=True, show_metric=True, batch_size=64, snapshot_step=200,
- snapshot_epoch=False, run_id='alexnet_test')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement