Skip to content

Commit

Permalink
Merge pull request #100 from Aydinhamedi/Alpha-b
Browse files Browse the repository at this point in the history
Alpha b
  • Loading branch information
Aydinhamedi authored Jan 10, 2024
2 parents 6e48def + 9967deb commit 87909fa
Show file tree
Hide file tree
Showing 8 changed files with 2,611 additions and 42,498 deletions.
21,276 changes: 37 additions & 21,239 deletions BETA_E_Model_T&T.ipynb

Large diffs are not rendered by default.

2,490 changes: 2,490 additions & 0 deletions Exports/V7/Python_EPO.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Interface/CLI/Data/CLI_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def CI_pwai(Auto: bool = False):
model, 'top_activation',
second_last_conv_layer_name = 'top_conv',
sensitivity_map = 2, pred_index=tf.argmax(model_prediction_ORG[0]))
Grad_cam_heatmap = cv2.resize(Grad_cam_heatmap, (img_array.shape[1], img_array.shape[2]))
Grad_cam_heatmap = cv2.resize(np.clip(Grad_cam_heatmap, 0, 1), (img_array.shape[1], img_array.shape[2]))
Grad_cam_heatmap = np.uint8(255 * Grad_cam_heatmap)
Grad_cam_heatmap = cv2.applyColorMap(Grad_cam_heatmap, cv2.COLORMAP_VIRIDIS)
Grad_cam_heatmap = np.clip(np.uint8((Grad_cam_heatmap * 0.3) + ((img_array * 255) * 0.7)), 0, 255)
Expand Down
10 changes: 3 additions & 7 deletions Interface/CLI/Data/Utils/Grad_cam.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
import glob
import numpy as np
import tensorflow as tf
# Other
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
tf.get_logger().setLevel('ERROR')
physical_devices = tf.config.list_physical_devices('GPU')
for gpu_instance in physical_devices:
Expand Down Expand Up @@ -37,7 +39,7 @@ def make_gradcam_heatmap(img_array,
model,
last_conv_layer_name,
second_last_conv_layer_name=None,
pred_index=None, threshold=0,
pred_index=None,
sensitivity_map=1.0):
"""
Function to compute the Grad-CAM heatmap for a specific class, given an input image.
Expand All @@ -48,17 +50,11 @@ def make_gradcam_heatmap(img_array,

# Compute heatmap for the last convolutional layer
heatmap = _compute_heatmap(model, img_array, last_conv_layer_name, pred_index)

# Apply threshold and adjust sensitivity
heatmap = np.where(heatmap > threshold, heatmap, 0)
heatmap = heatmap ** sensitivity_map

if second_last_conv_layer_name is not None:
# Compute heatmap for the second last convolutional layer
heatmap_second = _compute_heatmap(model, img_array, second_last_conv_layer_name, pred_index)

# Apply threshold and adjust sensitivity
heatmap_second = np.where(heatmap_second > threshold, heatmap_second, 0)
heatmap_second = heatmap_second ** sensitivity_map

# Average the two heatmaps
Expand Down
33 changes: 33 additions & 0 deletions Interface/CLI/Run_CLI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import subprocess
import traceback
import sys
import os
# Other
from Data.Utils.print_color_V1_OLD import print_Color
def run_program(file_path):
while True:
try:
try:
# Run the other Python program using subprocess
subprocess.run(["python", file_path], check=True)
except subprocess.CalledProcessError as ERROR_Py:
print_Color("~*An error occurred: \nERROR: ~*" + str(ERROR_Py), ['yellow', 'red'], advanced_mode=True)
print_Color('~*Do you want to see the detailed error message? ~*[~*Y~*/~*n~*]: ',
['yellow', 'normal', 'green', 'normal', 'red', 'normal'],
advanced_mode = True,
print_END='')
show_detailed_error = input('')
if show_detailed_error.lower() == 'y':
print_Color('detailed error message:', ['yellow'])
#print_Color('1th ERROR (FILE ERROR) [!MAIN!]:', ['red'])
print_Color('2th ERROR (subprocess.run ERROR):', ['red'])
traceback.print_exc()
choice = input("Do you want to restart the program? (y/n): ")
if choice.lower() != "y":
break
os.system('cls' if os.name == 'nt' else 'clear')
else:
break
except OSError:
break
run_program('Data\CLI_main.py')
21,276 changes: 37 additions & 21,239 deletions Model_T&T.ipynb

Large diffs are not rendered by default.

10 changes: 3 additions & 7 deletions Utils/Grad_cam.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
import glob
import numpy as np
import tensorflow as tf
# Other
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
tf.get_logger().setLevel('ERROR')
physical_devices = tf.config.list_physical_devices('GPU')
for gpu_instance in physical_devices:
Expand Down Expand Up @@ -37,7 +39,7 @@ def make_gradcam_heatmap(img_array,
model,
last_conv_layer_name,
second_last_conv_layer_name=None,
pred_index=None, threshold=0,
pred_index=None,
sensitivity_map=1.0):
"""
Function to compute the Grad-CAM heatmap for a specific class, given an input image.
Expand All @@ -48,17 +50,11 @@ def make_gradcam_heatmap(img_array,

# Compute heatmap for the last convolutional layer
heatmap = _compute_heatmap(model, img_array, last_conv_layer_name, pred_index)

# Apply threshold and adjust sensitivity
heatmap = np.where(heatmap > threshold, heatmap, 0)
heatmap = heatmap ** sensitivity_map

if second_last_conv_layer_name is not None:
# Compute heatmap for the second last convolutional layer
heatmap_second = _compute_heatmap(model, img_array, second_last_conv_layer_name, pred_index)

# Apply threshold and adjust sensitivity
heatmap_second = np.where(heatmap_second > threshold, heatmap_second, 0)
heatmap_second = heatmap_second ** sensitivity_map

# Average the two heatmaps
Expand Down
12 changes: 7 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
tensorflow==2.10.1
keras==2.10.0
absl-py==1.4.0
adabelief-tf==0.2.1
efficientnet==1.1.1
gpu-control==1.0.0
hyperas==0.4.1
imbalanced-learn==0.11.0
keras==2.10.0
keras-adabound==0.6.0
keras-efficientnet-v2==1.2.2
keras-gradient-noise==0.11
Expand All @@ -15,12 +14,15 @@ model-profiler==1.1.8
numpy==1.25.1
opencv-python==4.8.0.74
pandas==2.0.3
Pillow==10.1.0
Pillow==10.2.0
psutil==5.9.5
py-cpuinfo==9.0.0
pydicom==2.4.3
requests==2.31.0
scikit-learn==1.3.0
scipy==1.11.1
seaborn==0.12.2
tensorflow==2.10.1
tensorflow-addons==0.22.0
tensorflow-model-optimization==0.7.5
tqdm==4.66.1
imblearn~=0.0
future~=0.18.3

0 comments on commit 87909fa

Please sign in to comment.