-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3_color_analysis.py
More file actions
102 lines (66 loc) · 2.86 KB
/
Copy path3_color_analysis.py
File metadata and controls
102 lines (66 loc) · 2.86 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""
This file contains a toy examples to have a first contact with Nefesi, and Keras.
This file has been created with tensorflow (and tensorflow-gpu) 1.8.0, keras 2.2.0, and python 3.6 (with anaconda3 interpreter)
"""
import cv2
import torch
from torchvision import transforms
import numpy as np
import functools
from functions.network_data2 import NetworkData
import types
import functions.GPUtil as gpu
BATCH_SIZE = 100
from functions.image import ImageDataset
from functions.read_activations import get_activations
import interface_DeepFramework.DeepFramework as DeepF
import matplotlib.pyplot as plt
def preproces_imagenet_img( imgs_hr):
img=np.array(imgs_hr)
tnsr = [transforms.ToTensor()(img)]
return tnsr
def main():
#Here You can find all the funcitons that allow us to visualize and quantify a trained Neural Network.
# To perform the calculation taking into acount the negative activations instead of positives, uncoment line 53 in the file read_activations
# Load the Model with your weigths first
# folder_dir ="C:/Users/arias/Desktop/Nefesi2022/"
folder_dir = "/home/guillem/Nefesi2022/"
# device = torch.device("cuda" if torch.cuda.is_available()
# else "cpu")
# model = torch.load( folder_dir+'Nefesi/Model_generation/Savedmodel/vgg16_class_positive')
Nefesimodel= NetworkData.load_from_disk(folder_dir+'nefesi/Nefesi_models/UNet/UNet_pos')
layers=Nefesimodel.get_layer_names_to_analyze()
for l in layers:
plt.subplot(3,3,1)
neurona = Nefesimodel.get_neuron_of_layer(l, 0)
print(neurona._neuron_feature)
plt.imshow(neurona._neuron_feature/256)
plt.subplot(3, 3, 2)
neurona2 = Nefesimodel.get_neuron_of_layer(l, 1)
plt.imshow(neurona2._neuron_feature / 256)
plt.subplot(3, 3, 3)
neurona3 = Nefesimodel.get_neuron_of_layer(l, 2)
plt.imshow(neurona3._neuron_feature / 256)
plt.subplot(3, 3, 4)
neurona3 = Nefesimodel.get_neuron_of_layer(l, 3)
plt.imshow(neurona3._neuron_feature / 256)
plt.subplot(3, 3, 5)
neurona3 = Nefesimodel.get_neuron_of_layer(l, 4)
plt.imshow(neurona3._neuron_feature / 256)
plt.subplot(3, 3, 6)
neurona3 = Nefesimodel.get_neuron_of_layer(l, 5)
plt.imshow(neurona3._neuron_feature / 256)
plt.subplot(3, 3, 7)
neurona3 = Nefesimodel.get_neuron_of_layer(l, 6)
plt.imshow(neurona3._neuron_feature / 256)
plt.subplot(3, 3, 8)
neurona3 = Nefesimodel.get_neuron_of_layer(l, 7)
plt.imshow(neurona3._neuron_feature / 256)
plt.subplot(3, 3, 9)
neurona3 = Nefesimodel.get_neuron_of_layer(l, 8)
plt.imshow(neurona3._neuron_feature / 256)
plt.show()
print(neurona3.activations)
print(neurona3.images_id)
if __name__ == '__main__':
main()