Spaces:
Runtime error
Runtime error
small fix to video
Browse files- create_video.py +4 -10
- grad_cam.py +0 -10
- load_disease_info.py +0 -4
- overlay_image.py +0 -3
- packages.txt +1 -0
create_video.py
CHANGED
@@ -18,7 +18,7 @@ def noise_process(numpy_image, steps=149):
|
|
18 |
def generate_video(numpy_image):
|
19 |
save_path = "result.mp4"
|
20 |
width = 256
|
21 |
-
|
22 |
fps = 30
|
23 |
sec = 5
|
24 |
image_lst = noise_process(numpy_image)
|
@@ -29,16 +29,10 @@ def generate_video(numpy_image):
|
|
29 |
image_lst = np.repeat(image_lst, copies, axis=0)
|
30 |
image_lst = np.concatenate((image_lst, image_lst[:spill_over]), axis=0)
|
31 |
image_lst = image_lst[::-1]
|
32 |
-
fourcc = cv2.VideoWriter_fourcc(*'
|
33 |
-
video = cv2.VideoWriter(save_path, fourcc, float(fps), (width,
|
34 |
for frame_count in range(fps * sec):
|
35 |
-
img = np.expand_dims(image_lst[frame_count],2)
|
36 |
video.write(img.astype(np.uint8))
|
37 |
video.release()
|
38 |
return save_path
|
39 |
-
|
40 |
-
|
41 |
-
if __name__ == "__main__":
|
42 |
-
im = Image.open(r"C:\Users\folle\Downloads\ldm_images\Atelectasis\0_4.png")
|
43 |
-
im_to_disp = np.array(im)
|
44 |
-
generate_video(im_to_disp)
|
18 |
def generate_video(numpy_image):
|
19 |
save_path = "result.mp4"
|
20 |
width = 256
|
21 |
+
height = 256
|
22 |
fps = 30
|
23 |
sec = 5
|
24 |
image_lst = noise_process(numpy_image)
|
29 |
image_lst = np.repeat(image_lst, copies, axis=0)
|
30 |
image_lst = np.concatenate((image_lst, image_lst[:spill_over]), axis=0)
|
31 |
image_lst = image_lst[::-1]
|
32 |
+
fourcc = cv2.VideoWriter_fourcc(*'avc1')
|
33 |
+
video = cv2.VideoWriter(save_path, fourcc, float(fps), (width, height))
|
34 |
for frame_count in range(fps * sec):
|
35 |
+
img = np.expand_dims(image_lst[frame_count], 2)
|
36 |
video.write(img.astype(np.uint8))
|
37 |
video.release()
|
38 |
return save_path
|
|
|
|
|
|
|
|
|
|
|
|
grad_cam.py
CHANGED
@@ -69,11 +69,9 @@ class GradCamGenerator:
|
|
69 |
image_PIL.save(gc_filename)
|
70 |
|
71 |
def transform_pil_to_tensor(self, pil_image):
|
72 |
-
# ImageNet mean and std
|
73 |
mean = [0.485, 0.456, 0.406]
|
74 |
std = [0.229, 0.224, 0.225]
|
75 |
|
76 |
-
# transformation to be applied
|
77 |
transform = transforms.Compose([
|
78 |
transforms.Resize(224),
|
79 |
transforms.ToTensor(),
|
@@ -83,7 +81,6 @@ class GradCamGenerator:
|
|
83 |
return tensor.unsqueeze(0)
|
84 |
|
85 |
def pil_loader(self, path, n_channels):
|
86 |
-
# open path as file to avoid ResourceWarning (https://github.com/python-pillow/Pillow/issues/835)
|
87 |
with open(path, 'rb') as f:
|
88 |
img = Image.open(f)
|
89 |
if n_channels == 1:
|
@@ -102,10 +99,3 @@ def create_GC_from_folder(path, classifier='checkpoint', layer_name='features.no
|
|
102 |
(not os.path.exists(cf+'/'+f[:-4]+'_overlay.png') or not overlay))]
|
103 |
for cfil in tqdm(files):
|
104 |
GC.generate_grad_cam(cfil)
|
105 |
-
#GCmap = GC.generate_grad_cam(cfil)
|
106 |
-
#GC.save_img(GCmap, cfil)
|
107 |
-
|
108 |
-
if __name__=='__main__':
|
109 |
-
import matplotlib.pyplot as plt
|
110 |
-
path = 'data/'
|
111 |
-
create_GC_from_folder(path)
|
69 |
image_PIL.save(gc_filename)
|
70 |
|
71 |
def transform_pil_to_tensor(self, pil_image):
|
|
|
72 |
mean = [0.485, 0.456, 0.406]
|
73 |
std = [0.229, 0.224, 0.225]
|
74 |
|
|
|
75 |
transform = transforms.Compose([
|
76 |
transforms.Resize(224),
|
77 |
transforms.ToTensor(),
|
81 |
return tensor.unsqueeze(0)
|
82 |
|
83 |
def pil_loader(self, path, n_channels):
|
|
|
84 |
with open(path, 'rb') as f:
|
85 |
img = Image.open(f)
|
86 |
if n_channels == 1:
|
99 |
(not os.path.exists(cf+'/'+f[:-4]+'_overlay.png') or not overlay))]
|
100 |
for cfil in tqdm(files):
|
101 |
GC.generate_grad_cam(cfil)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
load_disease_info.py
CHANGED
@@ -10,7 +10,3 @@ def disease_info(disease_index):
|
|
10 |
html_text += "<h1>Symptoms</h1>\n" + "<p>" + str(df["Symptoms"]) + "</p>" + "<br><br>"
|
11 |
html_text += "<h1>Treatment</h1>\n" + "<p>" + str(df["Treatment"]) + "</p>" + "<br><br>"
|
12 |
return html_text
|
13 |
-
|
14 |
-
|
15 |
-
if __name__ == "__main__":
|
16 |
-
disease_info("Pneumothorax")
|
10 |
html_text += "<h1>Symptoms</h1>\n" + "<p>" + str(df["Symptoms"]) + "</p>" + "<br><br>"
|
11 |
html_text += "<h1>Treatment</h1>\n" + "<p>" + str(df["Treatment"]) + "</p>" + "<br><br>"
|
12 |
return html_text
|
|
|
|
|
|
|
|
overlay_image.py
CHANGED
@@ -18,6 +18,3 @@ def overlay_numpy(im, heat_map, path):
|
|
18 |
file_name = os.path.splitext(path)[0] + '_overlay.png'
|
19 |
fig.savefig(file_name, bbox_inches='tight', pad_inches=0, transparent=True, dpi=1200)
|
20 |
plt.close()
|
21 |
-
|
22 |
-
if __name__=='__main__':
|
23 |
-
overlay_file('1_99.png', '1_99_gc.png')
|
18 |
file_name = os.path.splitext(path)[0] + '_overlay.png'
|
19 |
fig.savefig(file_name, bbox_inches='tight', pad_inches=0, transparent=True, dpi=1200)
|
20 |
plt.close()
|
|
|
|
|
|
packages.txt
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
ubuntu-restricted-extras
|