# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# + colab={"base_uri": "https://localhost:8080/", "height": 1105} colab_type="code" executionInfo={"elapsed": 14392, "status": "ok", "timestamp": 1554066245719, "user": {"displayName": "<NAME>", "photoUrl": "https://lh5.googleusercontent.com/-gky4Rdx3FyM/AAAAAAAAAAI/AAAAAAAAB1w/n8k1h4Eyqt8/s64/photo.jpg", "userId": "02667765190758511137"}, "user_tz": 240} id="Wx3nOpUi02-L" outputId="d3c1494b-8e58-4276-a353-40f23145d7c3"
# !wget https://github.com/MNRKhan/aps360-project/raw/master/baseline_watershed/baseline_watershed.py
# !wget https://github.com/MNRKhan/aps360-project/raw/master/modules/data_loader.py
# !wget https://github.com/MNRKhan/aps360-project/raw/master/modules/metrics.py
# !wget https://github.com/MNRKhan/aps360-project/raw/master/modules/visualizer.py

# + colab={} colab_type="code" id="dXCEOX-qCANF"
import numpy as np
import random
import torch
from torch.utils.data import DataLoader
from torchvision import transforms

from baseline_watershed import *
from data_loader import *
from metrics import *
from visualizer import *

# + colab={"base_uri": "https://localhost:8080/", "height": 337535} colab_type="code" executionInfo={"elapsed": 34700, "status": "ok", "timestamp": 1554066266080, "user": {"displayName": "<NAME>", "photoUrl": "https://lh5.googleusercontent.com/-gky4Rdx3FyM/AAAAAAAAAAI/AAAAAAAAB1w/n8k1h4Eyqt8/s64/photo.jpg", "userId": "02667765190758511137"}, "user_tz": 240} id="-CsW_KtgBqTj" outputId="63f52d8e-b79f-4ed3-91b4-aa400241bd15"
# !rm -rf __MACOSX
# !rm -rf *.zip
# !wget https://github.com/MNRKhan/aps360-project/raw/master/datasets/train2014/data_person_vehicle.zip
# !unzip data_person_vehicle.zip
# !rm -rf __MACOSX
# !rm -rf *.zip

# + colab={} colab_type="code" id="cw4052i7RyQX"
# Set random seeds
torch.manual_seed(360)
np.random.seed(360)
random.seed(360)

# Form dataset
transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
dataset = ImageMaskDataset("./data", transform, size=1000)

# Dataset sizes
size = len(dataset)
train_size = int(0.6 * size)
valid_size = int(0.2 * size)
test_size = size - train_size - valid_size

# Splitting datasets
train_data, valid_data, test_data = torch.utils.data.random_split(dataset, [train_size, valid_size, test_size])

# Making dataloader
valid = DataLoader(valid_data, batch_size=1, shuffle=True, num_workers=0)

# + colab={"base_uri": "https://localhost:8080/", "height": 68} colab_type="code" executionInfo={"elapsed": 34661, "status": "ok", "timestamp": 1554066266086, "user": {"displayName": "<NAME>", "photoUrl": "https://lh5.googleusercontent.com/-gky4Rdx3FyM/AAAAAAAAAAI/AAAAAAAAB1w/n8k1h4Eyqt8/s64/photo.jpg", "userId": "02667765190758511137"}, "user_tz": 240} id="f4FP9AztIg3l" outputId="8232a01c-b8db-4704-e380-c81c73c352e4"
print("Full data set: ", size)
print("Training size: ", train_size)
print("Validation size: ", valid_size)

# + colab={"base_uri": "https://localhost:8080/", "height": 34} colab_type="code" executionInfo={"elapsed": 46930, "status": "ok", "timestamp": 1554066278368, "user": {"displayName": "<NAME>", "photoUrl": "https://lh5.googleusercontent.com/-gky4Rdx3FyM/AAAAAAAAAAI/AAAAAAAAB1w/n8k1h4Eyqt8/s64/photo.jpg", "userId": "02667765190758511137"}, "user_tz": 240} id="8t0KVathWdSc" outputId="5a84aad2-78df-4a72-bbe5-4a8365170004"
print(watershed_iou(valid_data))

# + colab={} colab_type="code" id="7wB4hlQfiYl-"


StarcoderdataJupyterScriptsDedupFiltered