print "Learning step: " + str(learning_step_current_nr) + "..." # Get image from training set. img_train_name = img_train_names[it] # Load the image and labels of image with name 'img_train_name' img_train = np.load(TRAINING_AND_TESTING_DATA_ROOT + "img_npy/" + img_train_name) labels_train = np.load( TRAINING_AND_TESTING_DATA_ROOT + "labels_npy/" + img_train_name.replace("_img.npy", "_labels.npy") ) # Preprocess the data before loading it into FCN. img_train_FCN_ready = lib.rgb_to_bgr(img_train) img_train_FCN_ready = lib.subtract_bgr_channel_means( img=img_train_FCN_ready, blue_mean=channel_means["blue_mean"], green_mean=channel_means["green_mean"], red_mean=channel_means["red_mean"], ) img_train_FCN_ready = img_train_FCN_ready.transpose(2, 0, 1).reshape(1, 3, 500, 500) labels_train_FCN_ready = labels_train.reshape(1, 1, 500, 500) # Load image and labels into FCN. solver.net.blobs["data"].data[...] = img_train_FCN_ready solver.net.blobs["label"].data[...] = labels_train_FCN_ready # Make one training step. solver.step(1) # Measure and temporarily store the loss every 'loss_interval' training steps. if it % loss_interval == 0: loss_temp = float(solver.net.blobs["loss"].data)
# Print current learning step. print "Learning step: " + str(learning_step_current_nr) + '...' # Get image from training set. img_train_name = img_train_names[it] # Load the image and labels of image with name 'img_train_name' img_train = np.load(TRAINING_AND_TESTING_DATA_ROOT + 'img_npy/' + img_train_name) labels_train = np.load(TRAINING_AND_TESTING_DATA_ROOT + 'labels_npy/' + img_train_name.replace('_img.npy', '_labels.npy')) # Preprocess the data before loading it into FCN. img_train_FCN_ready = lib.rgb_to_bgr(img_train) img_train_FCN_ready = lib.subtract_bgr_channel_means(img=img_train_FCN_ready, blue_mean=channel_means['blue_mean'], green_mean=channel_means['green_mean'], red_mean=channel_means['red_mean']) img_train_FCN_ready = img_train_FCN_ready.transpose(2, 0, 1).reshape(1, 3, 500, 500) labels_train_FCN_ready = labels_train.reshape(1, 1, 500, 500) # Load image and labels into FCN. solver.net.blobs['data'].data[...] = img_train_FCN_ready solver.net.blobs['label'].data[...] = labels_train_FCN_ready # Make one training step. solver.step(1) # Measure and temporarily store the loss every 'loss_interval' training steps. if it % loss_interval == 0: loss_temp = float(solver.net.blobs['loss'].data) loss_current.append(loss_temp)
labels_predicted = np.argmax(scores, 2).astype(np.uint8) lib.plot_sat_image_and_labels(img=img_cropped, lab=labels_predicted, alpha=0.5, plot_img=True, store_img=False, plot_with='pyplot', dir_name=RESULTS_ROOT, file_name='test_image_x_' + area_name + RUN_NAME + str(number_of_training_steps), cmap=cmap1) img = lib.rgb_to_bgr(img) blue_mean = channel_means['blue_mean'] green_mean = channel_means['green_mean'] red_mean = channel_means['red_mean'] img = lib.subtract_bgr_channel_means(img, blue_mean, green_mean, red_mean) tiles_of_image = lib.image_to_tiles(img=img, hgh=500, wdt=500) net.predict([tiles_of_image[0, 0, :, :, :]], oversample=False) caffe_out = net.blobs['score'].data[0, :, :, :] asdf = np.argmax(caffe_out, 0).astype(np.uint8) lib.plot_sat_image_and_labels(img=img_cropped, lab=asdf, alpha=0.5, plot_img=False, store_img=True, plot_with='Image', dir_name=RESULTS_ROOT,