-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
86 lines (59 loc) · 2.66 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
78
79
80
81
82
83
84
85
86
'''
Driver (Main) file.
'''
import numpy as np
from PIL import Image
import resource
import random
from tqdm import tqdm
import cv2
import matplotlib.pyplot as plt
import os
import sys
import psutil
import time
from simulate_and_save import *
if __name__ == '__main__':
# ______________ STEP 1__________________
# Generating the parasite and veins image and saving them as .tif in the data directiory (less than 500 kb)
session = 1
# Initialie the simulation for this session
tock = time.time()
simulate = Simulate(size = (cfg.INPUT_SIZE, cfg.INPUT_SIZE), visualize = False, sess_num = session)
# Generate fake parasite and fake veins to simulate. This will save the parasite image by default as a compressed .tif file
parasite = simulate.generate_fake_parasite()
usage = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1024
print("Memory Occupied is", usage, "MB")
veins_all, veins_body = simulate.generate_fake_veins(has_cancer = False)
# Calculate if the parasite has cancer or not
overlap = simulate.calculate_overlap(parasite, veins_body)
tick = time.time()
print("Time taken to run is", tick-tock, "seconds.")
print("-------- PART 1 RESULTS ---------")
if overlap > cfg.CANCER_THRESHOLD:
print("!!!!The parasite", session, "has cancer. Saving the veins image.!!!!")
simulate.sparse_save(veins_all)
else:
print("No cancer detected in the parasite", session)
print("Overlap found to be", overlap)
usage = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1024
print("Memory Occupied is", usage, "MB")
print("__________________________________________________________________________________________")
# Deleting the object to free space
del simulate
# _______________STEP 2____________________
# Importing the saved image, decompressing it, and findind if the parasite has cancer or not
# session = 2
# simulate = Simulate(size = (10000, 10000), visualize = False, sess_num = session)
# parasite = simulate.generate_fake_parasite()
# veins_all, veins_body = simulate.generate_fake_veins(has_cancer = True)
# overlap = simulate.calculate_overlap(parasite, veins_body)
# print("-------- PART 2 RESULTS ---------")
# if overlap > cfg.CANCER_THRESHOLD:
# print("!!!!The parasite", session, "has cancer. Saving the veins image.!!!!")
# simulate.sparse_save(veins_all)
# else:
# print("No cancer detected in the parasite", session)
# print("Overlap found to be", overlap)
# print("__________________________________________________________________________________________")
# del simulate