Guest User

Untitled

a guest
Mar 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. # UCF Senior Design 2017-18
  2. # Group 38
  3.  
  4. from sklearn.model_selection import train_test_split as tts
  5. import pickle
  6. import tflearn
  7. import os
  8. import yaml
  9.  
  10. DATASET = 'leavens.pkl'
  11. OUTPUT_FOLDER = '/output/buff_bobo'
  12. SEED = 3
  13.  
  14. # Residual blocks
  15. # 32 layers: n=5, 56 layers: n=9, 110 layers: n=18
  16. n = 5
  17.  
  18. # Real-time data preprocessing
  19. img_prep = tflearn.ImagePreprocessing()
  20. img_prep.add_featurewise_zero_center(per_channel=True)
  21.  
  22. # Real-time data augmentation
  23. img_aug = tflearn.ImageAugmentation()
  24. img_aug.add_random_flip_leftright()
  25.  
  26. with open(DATASET, 'rb') as f:
  27. pickle = pickle.load(f, encoding='latin1')
  28.  
  29. x = pickle['x']
  30. y = pickle['y']
  31. (X, X_test, Y, Y_test) = tts(x, y, test_size=0.3, random_state=SEED)
  32.  
  33. X, Y = tflearn.data_utils.shuffle(X, Y)
  34.  
  35. net = tflearn.input_data(shape=[None, 448, 448, 3],
  36. data_preprocessing=img_prep,
  37. data_augmentation=img_aug)
  38.  
  39. net = tflearn.conv_2d(net, 64, 3, regularizer='L2', weight_decay=0.0001)
  40. net = tflearn.residual_block(net, n, 64)
  41. net = tflearn.residual_block(net, 1, 128, downsample=True)
  42. net = tflearn.residual_block(net, n-1, 128)
  43. net = tflearn.residual_block(net, 1, 256, downsample=True)
  44. net = tflearn.residual_block(net, n-1, 256)
  45. net = tflearn.residual_block(net, 1, 512, downsample=True)
  46. net = tflearn.residual_block(net, n-1, 512)
  47. net = tflearn.batch_normalization(net)
  48. net = tflearn.activation(net, 'relu')
  49. net = tflearn.global_avg_pool(net)
  50.  
  51. net = tflearn.fully_connected(net, 2, activation='softmax')
  52. mom = tflearn.Momentum(0.1, lr_decay=0.1, decay_step=32000, staircase=True)
  53. net = tflearn.regression(net, optimizer='adam',
  54. loss='categorical_crossentropy')
  55.  
  56. # Training
  57. model = tflearn.DNN(net, checkpoint_path=OUTPUT_FOLDER,
  58. max_checkpoints=10, tensorboard_verbose=3,
  59. clip_gradients=0.)
  60.  
  61. model.fit(X, Y, n_epoch=200, validation_set=(X_test, Y_test),
  62. show_metric=True, batch_size=32, shuffle=True,
  63. run_id='buff_bobo')
  64.  
  65. model_name = "buff_bobo" + ".tfl"
  66. model_path = os.path.join(OUTPUT_FOLDER, model_name)
  67. model.save(model_path)
Add Comment
Please, Sign In to add comment