daily pastebin goal
42%
SHARE
TWEET

itdonmatteratall

a guest Jan 18th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from keras.models import Sequential
  4. from keras.layers.convolutional import Conv2D
  5. from keras.layers.core import Dense, Dropout, Activation, Flatten
  6. from keras.layers.convolutional import Convolution2D, MaxPooling2D, ZeroPadding2D
  7. from keras.layers.normalization import BatchNormalization
  8. #from sklearn.preprocessing import LabelEncoder
  9. #from sklearn.preprocessing import OneHotEncoder
  10. import copy
  11. import cv2
  12. import pickle
  13. #from keras.optimizers import Adam
  14. #from keras.preprocessing.image import ImageDataGenerator
  15. from keras.callbacks import EarlyStopping
  16.  
  17. dim = 200
  18.  
  19. print("[INFO] Importing Data...")
  20. pickle_in = open("train_xarr.pickle","rb")
  21. train_xarr = pickle.load(pickle_in)
  22.  
  23. pickle_in = open("val_xarr.pickle","rb")
  24. val_xarr = pickle.load(pickle_in)
  25.  
  26. #pickle_in = open("test_xarr.pickle","rb")
  27. #test_xarr = pickle.load(pickle_in)
  28.  
  29. pickle_in = open("train_yarr.pickle","rb")
  30. train_yarr = pickle.load(pickle_in)
  31.  
  32. pickle_in = open("val_yarr.pickle","rb")
  33. val_yarr = pickle.load(pickle_in)
  34.  
  35. #pickle_in = open("test_yarr.pickle","rb")
  36. #test_yarr = pickle.load(pickle_in)
  37.  
  38. train_xarr = train_xarr.reshape([-1, dim, dim,1])
  39. val_xarr = val_xarr.reshape([-1, dim, dim,1])
  40. #test_xarr = test_xarr.reshape([-1, dim, dim,1])
  41.  
  42. model = Sequential()
  43. model.add(Conv2D(64, 11, strides=4))
  44. model.add(ZeroPadding2D(2))
  45. model.add(Activation('relu'))
  46. model.add(MaxPooling2D(pool_size=3, strides=2))
  47.  
  48. model.add(Conv2D(192, 5))
  49. model.add(ZeroPadding2D(2))
  50. model.add(Activation('relu'))
  51. model.add(MaxPooling2D(pool_size=3, strides=2))
  52.  
  53. model.add(Conv2D(384, 3))
  54. model.add(ZeroPadding2D(1))
  55. model.add(Activation('relu'))
  56.  
  57. model.add(Conv2D(256, 3))
  58. model.add(ZeroPadding2D(1))
  59. model.add(Activation('relu'))
  60. model.add(MaxPooling2D(pool_size=3, strides=2))
  61.  
  62. model.add(Flatten())
  63. model.add(Dropout(0.5))
  64. model.add(Dense(4096, input_shape=(6 * 6 * 256, )))
  65. model.add(Activation('relu'))
  66. model.add(Dropout(0.5))
  67. model.add(Dense(4096))
  68. model.add(Activation('relu'))
  69. model.add(Dense(70))
  70. model.add(Activation('softmax'))
  71.  
  72. EPOCHS = 20
  73. #INIT_LR = 1e-3
  74. #BS = 50
  75. #opt = Adam(lr=INIT_LR, decay=INIT_LR / EPOCHS)
  76. model.compile(loss="categorical_crossentropy", optimizer='rmsprop',
  77.     metrics=["accuracy"])
  78. es = EarlyStopping(monitor='val_loss', min_delta=0, patience=0, verbose=0, mode='auto', baseline=None, restore_best_weights=False)
  79. #aug = ImageDataGenerator(rotation_range=30, width_shift_range=0.1,
  80. #   height_shift_range=0.1, shear_range=0.2, zoom_range=0.2,
  81. #   horizontal_flip=True, fill_mode="nearest")
  82.  
  83. #steps_per_epoch=len(train_xarr) // BS
  84. #validation_data=(val_xarr, val_yarr)
  85. print("[INFO] training network...")
  86. history = model.fit(train_xarr, train_yarr, epochs=EPOCHS, validation_data=(val_xarr, val_yarr), batch_size = 10, verbose=1)
  87. print("できた")
  88.  
  89. #print (model.summary())
  90.  
  91. """
  92. pickle_in = open("test_xarr.pickle","rb")
  93. test_xarr = pickle.load(pickle_in)
  94. pickle_in = open("test_yarr.pickle","rb")
  95. test_yarr = pickle.load(pickle_in)
  96. test_xarr = test_xarr.reshape([-1, dim, dim,1])
  97.  
  98. error_and_stuff_i_think = history.history
  99.  
  100. #test_loss, test_acc = model.evaluate(test_xarr, test_yarr)
  101.  
  102. train_predicts = model.predict_proba(train_xarr)
  103.  
  104. #yuh = test_yarr-predicts
  105. """
  106. model.save('aircraft_model.h5')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top