import sys sys.path.append("..") import helpers helpers.mask_busy_gpus(wait=False) from keras import backend as K import numpy as np from skimage import transform import cv2 from get_data import load_dataset, unpack train_images, train_bboxes, train_shapes = load_dataset("data", "train") val_images, val_bboxes, val_shapes = load_dataset("data", "val") SAMPLE_SHAPE = (32, 32, 3) from scores import iou_score # https://en.wikipedia.org/wiki/Jaccard_index def is_negative_bbox(new_bbox, true_bboxes, eps=1e-1): """Check if new bbox not in true bbox list. There bbox is 4 ints [min_row, min_col, max_row, max_col] without image index.""" for bbox in true_bboxes: if iou_score(new_bbox, bbox) >= eps: return False return True
import torch from sklearn.metrics import confusion_matrix import matplotlib.pyplot as plt import numpy as np import seaborn as sns import time from get_data import load_dataset # Hyper params epochs = 12 train_batch_size = 30 test_batch_size = 1000 l_r = 0.0005 momentum = 0.5 # Retrieve the data train_data, test_data = load_dataset(train_batch_size, test_batch_size) # References for the main idea of building the __init__/forward functions: # Training a Classifier — PyTorch Tutorials 1.7.1 documentation. 2020. # [ONLINE] Available at: https://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html. # [Accessed 17 December 2020]. # MNIST Handwritten Digit Recognition in PyTorch - Nextjournal. 2020. # [ONLINE] Available at: https://nextjournal.com/gkoehler/pytorch-mnist # [Accessed 17 December 2020]. class CNN(nn.Module): def __init__(self): super(CNN, self).__init__() # Set up the structure of layers for the network # Takes 1-channel images self.conv1 = nn.Conv2d(1, 10, 5)
import torchvision import torch from sklearn.metrics import confusion_matrix import matplotlib.pyplot as plt import numpy as np import seaborn as sns import time from get_data import load_dataset # Hyper params n_epochs = 10 batch_size_train = 35 batch_size_test = 1000 learning_rate = 0.05 # Retrieve the data train_loader, test_loader = load_dataset(batch_size_train, batch_size_test) # References for the main idea of building the __init__/forward functions: # Training a Classifier — PyTorch Tutorials 1.7.1 documentation. 2020. # [ONLINE] Available at: https://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html. # [Accessed 17 December 2020]. # MNIST Handwritten Digit Recognition in PyTorch - Nextjournal. 2020. # [ONLINE] Available at: https://nextjournal.com/gkoehler/pytorch-mnist # [Accessed 17 December 2020]. class SGD(nn.Module): def __init__(self): super(SGD, self).__init__() # Set up the structure of layers for the network self.fc1 = nn.Linear(784, 200) self.fc2 = nn.Linear(200, 100)
import tensorflow as tf from keras.models import Sequential from keras.layers import Conv2D from keras.layers import MaxPooling2D from keras.layers import Dense from keras.layers import Flatten from keras.layers import Dropout from keras.layers import BatchNormalization # from keras.optimizers import SGD from keras.utils import np_utils from keras.utils import to_categorical from keras.models import model_from_json from get_data import load_dataset #load_data() x_train, y_train, x_test, y_test, class_names = load_dataset('data') num_classes = len(class_names) image_size = 28 # Reshape and normalize x_train = x_train.reshape(x_train.shape[0], image_size, image_size, 1).astype('float32') x_test = x_test.reshape(x_test.shape[0], image_size, image_size, 1).astype('float32') x_train /= 255.0 x_test /= 255.0 # Convert class vectors to class matrices y_train = keras.utils.to_categorical(y_train, num_classes) y_test = keras.utils.to_categorical(y_test, num_classes)
from Network import Network import numpy as np import matplotlib.pyplot as plt from sklearn.metrics import confusion_matrix from sklearn.metrics import plot_confusion_matrix import seaborn as sns import time # you change the configuration for the network in the init of Network class print('\n') network = Network() print("Network initialized") print('\n') # retrieve data X_train, y_train, X_val, y_val, X_test, y_test = load_dataset() print("Data has been loaded") print("Number of images in dataset: ", len(X_train) + len(X_val)) print("Number of images to test on: ", len(X_test)) print('\n') # parameters for the network epochs = 30 minibatch_length = 35 print("Number of epochs: ", epochs) print("Minibatch length: ", minibatch_length) print('\n') print("Epochs have started!") print('\n')