-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
77 lines (60 loc) · 2.52 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#! /usr/bin/python
# -*- coding: utf-8 -*-
"""
This file is the main executable for Multi-Directional Contrastive Predictive Coding for Histology.
This file loads the arguments, sets random seed and runs a selected task.
"""
# Own Module Import
from utils import *
from config import *
from cnn_train import *
from cpc_train import *
#from representations import *
__author__ = "Jacob Carse"
__copyright__ = "Copyright 2020, Multi-Directional Contrastive Predictive Coding for Histology"
__credits__ = ["Jacob Carse", "Stephen McKenna"]
__license__ = "MIT"
__version__ = "0.0.1"
__maintainer__ = "Jacob Carse"
__email__ = "j.carse@dundee.ac.uk"
__status__ = "Development"
if __name__ == "__main__":
# Loads the arguments from a config file and command line arguments.
description = "An implementation of Multi-Directional Contrastive Predictive Coding for Histology."
arguments = load_arguments(description)
log(arguments, "Loaded Arguments:")
print_arguments(arguments)
# Sets the random seed if specified.
if arguments["seed"] != 0:
set_random_seed(arguments["seed"])
log(arguments, f"Set Random Seed to {arguments['seed']}")
# Gets device that is used for training the model.
device = get_device(arguments)
log(arguments, f"Running on Device: {device}")
# Trains and Tests a Contrastive Predictive Coding model.
if arguments["task"].lower() == "cpc":
train_cpc(arguments, device)
test_cpc(arguments, device)
# Trains a Contrastive Predictive Coding Model.
elif arguments["task"].lower() == "train_cpc":
train_cpc(arguments, device)
# Tests a Contrastive Predictive Coding Model.
elif arguments["task"].lower() == "test_cpc":
test_cpc(arguments, device)
# Trains and Tests a Convolutional Neural Network model.
elif arguments["task"].lower() == "cnn":
train_cnn(arguments, device)
test_cnn(arguments, device)
# Trains a Convolutional Neural Network Model.
elif arguments["task"].lower() == "train_cnn":
train_cnn(arguments, device)
# Tests a Convolutional Neural Network Model.
elif arguments["task"].lower() == "test_cnn":
test_cnn(arguments, device)
# Generates representations using a trained encoder.
elif arguments["task"].lower() == "representations":
pass
#make_representations(arguments, device)
# If no valid argument was presented.
else:
log(arguments, "Enter a valid task, 'cpc', 'train_cpc', 'test_cpc', 'cnn', train_cnn' or 'test_cnn'.")