Beispiel #1
0
cuda_available = torch.cuda.is_available()

BATCH_SIZE = 32
MAX_EPOCHS = 800
INIT_LR = 0.001
WEIGHT_DECAY = 0.00005
LR_DROP_MILESTONES = [400, 600]

train_file_dir = 'PATH/TO/TRAINING/ANNOTATIONS'
valid_file_dir = 'PATH/TO/VALIDATION/ANNOTATIONS'
train_img_dir = 'PATH/TO/876x657/IMAGES'
valid_img_dir = 'PATH/TO/768x576/IMAGES'
save_path = 'PATH/TO/SAVE/TRAINING/MODELS'

train_dataset = TrafficLightDataset(csv_file=train_file_dir,
                                    img_dir=train_img_dir)
valid_dataset = TrafficLightDataset(csv_file=valid_file_dir,
                                    img_dir=valid_img_dir)

train_dataloader = DataLoader(train_dataset,
                              batch_size=BATCH_SIZE,
                              shuffle=True,
                              num_workers=8)
valid_dataloader = DataLoader(valid_dataset,
                              batch_size=1,
                              shuffle=False,
                              num_workers=2)

net = LYTNet()

if cuda_available:
Beispiel #2
0
import time
from torch.utils.data import DataLoader
from LYTNet import LYTNet
from loss import my_loss
from helpers import direction_performance, display_image
from dataset import TrafficLightDataset
import matplotlib.pyplot as plt
import numpy as np

cuda_available = torch.cuda.is_available()

test_file_loc = '/home/user/Desktop/eyeDoPy/Annotations/testing_file.csv'
test_image_directory = '/home/user/Desktop/eyeDoPy/PTL_Dataset_768x576/'
MODEL_PATH = '/home/user/Desktop/eyeDoPy/Model/_final_weights'

dataset = TrafficLightDataset(csv_file=test_file_loc,
                              img_dir=test_image_directory)
dataloader = DataLoader(dataset, batch_size=1, shuffle=False, num_workers=2)

#load weights
net = LYTNet()
checkpoint = torch.load(MODEL_PATH)
net.load_state_dict(checkpoint)
net.eval()

if cuda_available:
    net = net.cuda()

loss_fn = my_loss

#storing data
running_loss = 0
valid_file_root = '/home/mv01/Desktop/ISEF 2018/new 5-fold files/valid_file_'
image_directory = '/home/mv01/Desktop/ISEF 2018/resized_photos_512_384'
MODEL_SAVE_PATH = '/home/mv01/Desktop/ISEF 2018/train_cycle_14'
WEIGHT_LOAD_PATH = '/home/mv01/Desktop/ISEF 2018/train_cycle_14_epoch_50_weights2'
#these save the data for each of the 10 folds
fold_valid_accuracies = []
fold_valid_losses = []
fold_valid_angle = []
fold_valid_start = []
fold_valid_end = []

#10-fold cross validation
for i in range(3,4):
    
    train_file_loc = train_file_root + str(i+1) + '.csv'
    train_dataset = TrafficLightDataset(csv_file = train_file_loc, root_dir = image_directory)
    valid_file_loc = valid_file_root + str(i+1) + '.csv'
    valid_dataset = ValidDataset(csv_file = valid_file_loc, root_dir = image_directory)
    
    train_dataloader = DataLoader(train_dataset, batch_size=BATCH_SIZE, shuffle=True, num_workers=8)
    valid_dataloader = DataLoader(valid_dataset, batch_size=1, shuffle=False, num_workers=2)
    
    net = MyNet()
    
    #checkpoint = torch.load(WEIGHT_LOAD_PATH)
    #net.load_state_dict(checkpoint['state_dict'])
    if cuda_available:
        net = net.cuda()
    
    
    loss_fn = my_loss