Hi brothers.
I am a Korean student majoring in civil engineering.
The professor asked me to submit a building detection model using CNN for my graduation thesis and I really want to die.
I don’t know anything about computer science. I have 2 weeks left to submit, but I have too much to prepare for graduation.
Can you help me? I think there are a lot of talented brothers here, and I need you to help me out.
I’ll be direct. Make me a Deep Learning model.
I’ve got all the datasets.
Anaconda, Python 3.6.7, Piotochgpu, etc.
I know my request is reckless and irresponsible. But I have to. I have never learned and I have no time.
What else should I add here?
import random
from os import listdir
from os.path import isfile, join

import click
import torch
import torch.nn as nn
from torch.autograd import Variable

from model.deconvnet import DeconvNet
from util.data_load import BuildingData
from util.data_load import get_data_loader
from torchvision.utils import save_image
from util import utils


@click.command()
@click.option('--data_path', type=str, default='../data/')
@click.option('--trn_path', type=str, default='train/')
@click.option('--test_path', type=str, default='test/')
@click.option('--in_ext', type=str, default='.tiff')
@click.option('--out_ext', type=str, default='.tif')
@click.option('--seed', type=int)
@click.option('--cuda', type=bool, default=True)
@click.option('--epochs', type=int, default=10000)
@click.option('--lr', type=float, default=1e-3)
@click.option('--decay', type=float, default=1e-5)
@click.option('--batch_size', type=int, default=100)
@click.option('--init_weights', type=bool, default=True)
@click.option('--early_stop', type=bool, default=True)
@click.option('--stop_iter', type=int, default=20)
def main(data_path, trn_path, test_path, in_ext, out_ext,
         seed, cuda, epochs, lr, decay, batch_size, init_weights,
         early_stop, stop_iter):
    if seed is None:
        seed = random.randint(1, 1000)
    utils.set_seed(seed)
    gpu_usage = torch.cuda.is_available() and cuda

    trn_in_path = data_path + trn_path + 'in/'
    trn_list = [f.split('.')[0] for f in listdir(trn_in_path)
                if isfile(join(trn_in_path, f))]
    trn_out_path = data_path + trn_path + 'out/'
    test_in_path = data_path + test_path + 'in/'
    test_list = [f.split('.')[0] for f in listdir(test_in_path)
                if isfile(join(test_in_path, f))]
    test_out_path = data_path + test_path + 'out/'
    trn_dataset = BuildingData(trn_in_path, trn_out_path,
                               trn_list, in_ext, out_ext)
    test_dataset = BuildingData(test_in_path, test_out_path,
                                test_list, in_ext, out_ext)
    trn_dataloader = get_data_loader(trn_dataset, batch_size, True)
    test_dataloader = get_data_loader(test_dataset, len(test_list), True)

    model = DeconvNet()
    if gpu_usage:
        model = model.cuda()
    criterion = nn.MSELoss()
    optimizer = torch.optim.Adam(model.parameters(),
                                 lr=lr, weight_decay=decay)
    for epoch in range(epochs):
        total_mse = 0.
        for batch_idx, (in_image, out_image) in enumerate(trn_dataloader, 0):
            in_image = Variable(in_image)
            out_image = Variable(out_image)
            if gpu_usage:
                in_image = in_image.cuda()
                out_image = out_image.cuda()
            output = model(in_image)
            loss = criterion(output, out_image)
            optimizer.zero_grad()
            loss.backward()
            optimizer.step()
            total_mse += loss.item()

        num_batchs = batch_idx + 1
        mean_mse = total_mse / num_batchs
        print('epoch [{}/{}], loss:{:.4f}'
              .format(epoch + 1, epochs, mean_mse))
        if epoch % 10 == 0:
            pic = utils.to_img(output.cpu().data)
            save_image(pic, '../data/dc_img/image_{}.png'.format(epoch))


if __name__ == '__main__':
    main()