def not_mnist_test(): X, Y, Y_onehot = notMNIST_MNIST.load_notMNIST() # X.shape = (784, 10000), Y.shape = (1, 10000), Y_onehot.shape = (10, 10000) layer_types = [ 'relu', 'softmax', ] hidden_layer_dims = [ 100, ] parameters = nn_model.model(X, Y_onehot, hidden_layer_dims, layer_types, learning_rate=0.8, num_iterations=101, num_batches=10) Y_predict, train_accuracy = nn_model.predict(X, Y_onehot, parameters, hidden_layer_dims, layer_types) print('Training accuracy: %f' % train_accuracy) image_shape = (28, 28) sample_indices = [0, 10, 100, 200, 500, 1000, 2000, 5000, 9000] alphabet_list = np.array([chr(i) for i in range(ord('A'), ord('J') + 1)]) print(alphabet_list[list(map(int, Y[0, sample_indices]))]) print(alphabet_list[Y_predict[0, sample_indices]]) plot.display_image_samples(X, image_shape, sample_indices)
def handWriting_test(): X_train, Y_train = input_data.loadHandwritingTrainingData( ) #X_train.shape=(1024,387) Y_train.shape=(1,387) layer_types = ['sigmoid'] hidden_layer_dims = None parameters = nn_model.model(X_train, Y_train, hidden_layer_dims, layer_types, learning_rate=0.1, num_iterations=501) Y_train_predict, train_accuracy = nn_model.predict(X_train, Y_train, parameters, hidden_layer_dims, layer_types) print('Training accuracy: %f' % train_accuracy) X_test, Y_test = input_data.loadHandwritingTestData( ) #X_test.shape=(1024, 184) Y_train.shape=(1, 184) Y_test_predict, test_accuracy = nn_model.predict(X_test, Y_test, parameters, hidden_layer_dims, layer_types) print(Y_test[0, :10]) print(Y_test_predict[0, :10]) print('Test accuracy: %f' % test_accuracy)
def random_test(): X, Y, Y_onehot=input_data.loadRandomData() layer_types=['relu','softmax',] hidden_layer_dims=[120,] parameters = nn_model.model(X, Y_onehot, hidden_layer_dims, layer_types, learning_rate=0.5, num_iterations=2001, lambd=1.2) Y_predict, train_accuracy = nn_model.predict(X, Y_onehot, parameters, hidden_layer_dims, layer_types) train_accuracy = np.sum(Y_predict==Y) / Y.shape[1] print('Training accuracy: %f' % train_accuracy) plot.show_decision_boundry(X, Y, Y_onehot, nn_model.predict, parameters, hidden_layer_dims, layer_types)
def mnist_test(): X, Y, Y_onehot = notMNIST_MNIST.load_MINIST(10000) # X.shape = (784, 10000), Y.shape = (1, 10000), Y_onehot.shape = (10, 10000) layer_types=['softmax',] hidden_layer_dims=None parameters = nn_model.model(X, Y_onehot, hidden_layer_dims, layer_types, learning_rate=0.5, num_iterations=101, num_batches = 10) Y_predict, train_accuracy = nn_model.predict(X, Y_onehot, parameters, hidden_layer_dims, layer_types) print('Training accuracy: %f' % train_accuracy) image_shape = (28,28) sample_indices = [0,10,100,200,500,1000,2000,5000,9000] print(Y[0,sample_indices]) print(Y_predict[0,sample_indices]) plot.display_image_samples(X, image_shape, sample_indices)
def main(): """Contains all of the fucntion calls and puts the analysis together """ im1 = '/Users/dustin/CS/data/sat_images/bakken/S2B_MSIL1C_20190606T174919_N0207_R141_T13UFP_20190606T194941.SAFE/GRANULE/L1C_T13UFP_A011750_20190606T174937/IMG_DATA/T13UFP_20190606T174919_B03.jp2' #importing the image as a rasterio object satdat = prep_raster.img_read(im1) #getting some information on the raster image explore_raster.raster_info(satdat) explore_raster.raster_pixelres(satdat) #creating the bounding box and cropping the image based on the box box = (47.754309, -103.295, 47.865643, -103.030516) #the file name of the cropped image crop_fn = '/Users/dustin/CS/projects/oil_well_detector/data/sat_images/T13UFP_B03_crop_v2.tif' crop = prep_raster.img_crop(satdat, box, crop_fn) print(f'crop shape: {crop[0].shape}') crop1 = prep_raster.img_read(crop_fn) explore_raster.raster_info(crop1) poly_fn = '/Users/dustin/CS/projects/oil_well_detector/data/training_data/Wells_polygon_93_20190808.gpkg' polygon = prep_polygon.polygon_read(poly_fn, satdat.crs.to_epsg()) train_fn = '/Users/dustin/CS/projects/oil_well_detector/data/sat_images/well_labels_v2.tif' prep_polygon.polygon_2_raster(polygon, crop_fn, train_fn, crop[0].shape) #storing the metadata for the labels in lbl_meta and reshaping the labels as a vector in lbl_vec Y_data, Y_meta = prep_data.reshape(train_fn) X_data, X_meta = prep_data.reshape(crop_fn) print(f"X_data shape: {X_data.shape}") print(f"Y_data shape: {Y_data.shape}") # x_data_norm = prep_data.normalize(x_data) #this has an error X_train, X_dev, X_test, Y_train, Y_dev, Y_test = prep_data.data_split( X_data, Y_data, (0.8, 0.1, 0.1)) explore_data.describe(Y_dev) #explore_data.histogram(Y_dev.T) # sys.exit() print("\nNow starting with the neural network layers") layers_dims = [X_train.shape[0], 200, 90, 10, 1] tf.reset_default_graph() with tf.Session() as sess: print("\nCreate placeholders for the input and label data") X, Y = nn_layers.create_placeholders(X_data.shape[0], Y_data.shape[0]) print(f"X = {X}") print(f"Y = {Y}") print("\nInitialize the parameters") parameters = nn_layers.initialize(layers_dims, initialization='randn') for l in range(1, len(layers_dims)): print(f"W = {parameters['W'+str(l)]}") print(f"b = {parameters['b'+str(l)]}") print("\nCreate the computational graph") Z_L, cache = nn_forward_prop.forward_prop(X, parameters) print(f"Z_L: {Z_L}") print("\nCalculates the cost function") cost = nn_compute_cost.compute_cost(Z_L, Y) print(f"Cost: {cost}") print("\nRunning the model") parameters, Z_train, Z_test = nn_model.model(layers_dims, X_train, Y_train, X_test, Y_test, num_epochs=6) print("here I am") print("Z_train") explore_data.histogram(Z_train) explore_data.describe(Z_train) print("Z_test") explore_data.histogram(Z_test) explore_data.describe(Z_test)
test_set_y = test_set_y_orig.reshape(1, m) return test_set_x / 255, test_set_y test_set_x, test_set_y = read_test_data() train_set_x, train_set_y = read_train_data() learning_rates = [0.005, 0.003] results = {} for i in learning_rates: print('learning_rate:' + str(i)) results[str(i)] = nn_model.model(train_set_x, train_set_y, 4, test_set_x, test_set_y, num_iterations=100, learning_rate=i) for i in learning_rates: plt.plot(np.squeeze(results[str(i)]["costs"]), label=str(i)) plt.ylabel('cost') plt.xlabel('iterations') legend = plt.legend(loc='upper center', shadow=True) frame = legend.get_frame() frame.set_facecolor('0.90') plt.show()
def __init__(self): self.model = model() self.import_data("./training/")