Skip to content

Commit

Permalink
Merge pull request #196 from Aydinhamedi/Alpha-b
Browse files Browse the repository at this point in the history
Alpha b
  • Loading branch information
Aydinhamedi authored Mar 14, 2024
2 parents edf9cd1 + 12b754d commit 17802d3
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ruff_L&F.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
pip install ruff
- name: Lint with ruff
run: |
ruff check . --fix --show-fixes --statistics
ruff check . --fix --show-fixes
- name: Format with ruff
run: |
ruff format . --preview --line-length 140
48 changes: 26 additions & 22 deletions BETA_E_Model_T&T.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"from Utils.Grad_cam import make_gradcam_heatmap\n",
"from Utils.print_color_V2_NEW import print_Color_V2\n",
"from Utils.print_color_V1_OLD import print_Color\n",
"from Utils.Other import * # noqa: F403\n",
"from Utils.Other import * # noqa: F403\n",
"\n",
"# Other\n",
"tf.get_logger().setLevel(\"ERROR\")\n",
Expand Down Expand Up @@ -3214,10 +3214,12 @@
" layer.trainable = True\n",
"\n",
" # Combine the output of the two base models\n",
" combined = concatenate([\n",
" Dense(512, activation=\"relu\", kernel_regularizer=l2(0.01))(GlobalAveragePooling2D()(base_model1_out)),\n",
" Dense(512, activation=\"relu\", kernel_regularizer=l2(0.01))(GlobalAveragePooling2D()(base_model2_out)),\n",
" ])\n",
" combined = concatenate(\n",
" [\n",
" Dense(512, activation=\"relu\", kernel_regularizer=l2(0.01))(GlobalAveragePooling2D()(base_model1_out)),\n",
" Dense(512, activation=\"relu\", kernel_regularizer=l2(0.01))(GlobalAveragePooling2D()(base_model2_out)),\n",
" ]\n",
" )\n",
"\n",
" # adding CDL\n",
" Dense_L1 = Dense(1024, activation=\"relu\", kernel_regularizer=l2(0.02))(combined)\n",
Expand Down Expand Up @@ -9956,10 +9958,12 @@
"\n",
" old_weights, old_biases = layer.get_weights()\n",
"\n",
" layer.set_weights([\n",
" weight_initializer(shape=old_weights.shape),\n",
" bias_initializer(shape=len(old_biases)),\n",
" ])"
" layer.set_weights(\n",
" [\n",
" weight_initializer(shape=old_weights.shape),\n",
" bias_initializer(shape=len(old_biases)),\n",
" ]\n",
" )"
]
},
{
Expand Down Expand Up @@ -10356,14 +10360,14 @@
"\n",
"\n",
"# Funcs\n",
"def normalize_TO_RANGE(arr, min_val, max_val): # noqa: F811\n",
"def normalize_TO_RANGE(arr, min_val, max_val): # noqa: F811\n",
" arr = arr.astype(\"float32\")\n",
" arr = (arr - arr.min()) / (arr.max() - arr.min())\n",
" arr = arr * (max_val - min_val) + min_val\n",
" return arr\n",
"\n",
"\n",
"def Z_SCORE_normalize(arr): # noqa: F811\n",
"def Z_SCORE_normalize(arr): # noqa: F811\n",
" arr = arr.astype(\"float32\")\n",
" mean = np.mean(arr)\n",
" std_dev = np.std(arr)\n",
Expand Down Expand Up @@ -10613,8 +10617,8 @@
" advanced_mode=True,\n",
")\n",
"# warnings\n",
"P_warning(\"[RES_Train -> True].\") if RES_Train else None # noqa: F405\n",
"P_warning(\"[TerminateOnHighTemp_M -> False] GPU temperature protection is OFF\") if not TerminateOnHighTemp_M else None # noqa: F405\n",
"P_warning(\"[RES_Train -> True].\") if RES_Train else None # noqa: F405\n",
"P_warning(\"[TerminateOnHighTemp_M -> False] GPU temperature protection is OFF\") if not TerminateOnHighTemp_M else None # noqa: F405\n",
"print_Color(\"Setup Verbose END.\", [\"yellow\"])\n",
"# MAIN LOOP\n",
"try:\n",
Expand All @@ -10636,7 +10640,7 @@
" advanced_mode=True,\n",
" )\n",
" # warnings\n",
" P_warning(\"[TerminateOnHighTemp_M -> False] GPU temperature protection is OFF\") if not TerminateOnHighTemp_M else None # noqa: F405\n",
" P_warning(\"[TerminateOnHighTemp_M -> False] GPU temperature protection is OFF\") if not TerminateOnHighTemp_M else None # noqa: F405\n",
" # DP\n",
" if not AdvSubsetC:\n",
" print_Color(\"Shuffling data...\", [\"yellow\"])\n",
Expand Down Expand Up @@ -10860,7 +10864,7 @@
" # Garbage Collection (memory)\n",
" gc.collect()\n",
" tf.keras.backend.clear_session()\n",
" GPU_memUsage() # noqa: F405\n",
" GPU_memUsage() # noqa: F405\n",
" # Update TF summary text\n",
" for Key in TF_Summary_text_Dict:\n",
" TF_Summary_text_cache = f\"# @[{Key}].Data:\\n\"\n",
Expand Down Expand Up @@ -11200,10 +11204,10 @@
"from numba import cuda\n",
"\n",
"device = cuda.get_current_device()\n",
"GPU_memUsage() # noqa: F405\n",
"GPU_memUsage() # noqa: F405\n",
"print(\"Realising all memory...\")\n",
"device.reset()\n",
"GPU_memUsage() # noqa: F405\n",
"GPU_memUsage() # noqa: F405\n",
"print(\"done.\")"
]
},
Expand All @@ -11221,7 +11225,7 @@
"outputs": [],
"source": [
"# Save history\n",
"save_list(history, \"history\\\\model_history.pkl.gz\", compress=True) # noqa: F405"
"save_list(history, \"history\\\\model_history.pkl.gz\", compress=True) # noqa: F405"
]
},
{
Expand All @@ -11231,7 +11235,7 @@
"outputs": [],
"source": [
"# load history\n",
"history = load_list(\"history\\\\model_history.pkl.gz\", compressed=True) # noqa: F405"
"history = load_list(\"history\\\\model_history.pkl.gz\", compressed=True) # noqa: F405"
]
},
{
Expand Down Expand Up @@ -11705,9 +11709,9 @@
"\n",
"# Print acc\n",
"print(\"Val data acc:\")\n",
"evaluate_model_full(y_val, val_predictions) # noqa: F405\n",
"evaluate_model_full(y_val, val_predictions) # noqa: F405\n",
"print(\"Test data acc:\")\n",
"evaluate_model_full(y_test, test_predictions) # noqa: F405\n",
"evaluate_model_full(y_test, test_predictions) # noqa: F405\n",
"\n",
"# format data\n",
"val_predictions = np.argmax(val_predictions, axis=1)\n",
Expand Down Expand Up @@ -11824,7 +11828,7 @@
" plt.title(\"Number of Incorrect Predictions vs. Number of Data Points\")\n",
" plt.show()\n",
"except Exception:\n",
" P_warning(\"Failed to plot incorrect predictions vs. data points\") # noqa: F405"
" P_warning(\"Failed to plot incorrect predictions vs. data points\") # noqa: F405"
]
}
],
Expand Down
4 changes: 2 additions & 2 deletions Interface/CLI/Data/CLI_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# Utils
from Utils.Grad_cam import make_gradcam_heatmap
from Utils.print_color_V1_OLD import print_Color
from Utils.Other import * # noqa: F403
from Utils.Other import * # noqa: F403

# global vars>>>
# CONST SYS
Expand Down Expand Up @@ -463,7 +463,7 @@ def CI_tmwd(argv_Split: list = ["none"]):
else:
print("Training the model...\n")
# training
model.fit(images, labels, epochs=train_epochs, batch_size=1, verbose="auto")
model.fit(images, labels, epochs=train_epochs, batch_size=1, verbose="auto")
print("Training done.\n")
else:
print_Color(
Expand Down
8 changes: 4 additions & 4 deletions Interface/GUI/Data/GUI_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
sys.exit()
# global vars>>>
# CONST SYS
GUI_Ver = "0.9.3 Pre1"
GUI_Ver = "0.9.4"
Model_dir = "Data/PAI_model" # without file extention
Database_dir = "Data/dataset.npy"
IMG_AF = ("JPEG", "PNG", "BMP", "TIFF", "JPG", "DCM", "DICOM")
Expand Down Expand Up @@ -754,8 +754,8 @@ def main() -> None:
if not event == "-TIMEOUT-":
logger.debug(f"GUI_window:event: {event}")
logger.debug(f"GUI_window:values: {values}")
print(f"GUI_window:event: {event}")
print(f"GUI_window:values: {values}")
print(f"GUI_window:event: ~e[{event}]e~\n")
print(f"GUI_window:values: ~v[{values}]v~\n")

# Check if the window has been closed or the 'Close' button has been clicked
if event == sg.WINDOW_CLOSED or event == "Close":
Expand Down Expand Up @@ -835,7 +835,7 @@ def main() -> None:
# Retrieve the result from the queue
result_expanded = ""
result = GUI_Queue["-Main_log-"].get()
print(f"Queue Data: {result}")
print(f"Queue Data: {result}\n")
logger.debug(f"Queue[-Main_log-]:get: {result}")
# Update the GUI with the result message
for block in result:
Expand Down
6 changes: 4 additions & 2 deletions Interface/GUI/GUI.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ for /F "usebackq delims==" %%i in ("Data\requirements.txt") do (
REM Write the current Python version + Python install time to the file
echo %current_python_version% > %PV_filepath%
@REM Pause for user input
echo Press any key to load the GUI...
pause > nul
if not "%Full_Auto%"=="1" (
echo Press any key to load the GUI...
pause > nul
)

:FAST_START
REM Print the appropriate loading message
Expand Down
1 change: 0 additions & 1 deletion Interface/GUI/README.txt

This file was deleted.

19 changes: 17 additions & 2 deletions Interface/GUI/Silent_Run.vbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "GUI.cmd" & Chr(34), 0
Set WshShell = Nothing
Set FSO = CreateObject("Scripting.FileSystemObject")

' Define the path to the file you want to check
filePath = "Data\Python Ver.tmp"

' Check if the file exists
If FSO.FileExists(filePath) Then
' If the file exists, run it without showing a window
WshShell.Run chr(34) & "GUI.cmd" & Chr(34), 0, False
Else
' If the file does not exist, run GUI.cmd with a terminal window and show a popup message
WshShell.Run chr(34) & "GUI.cmd" & Chr(34), 1, False
WshShell.Popup "This is the first time running the GUI. It may take a few minutes to start.", 30, "First Time Running", 64
End If

Set WshShell = Nothing
Set FSO = Nothing
48 changes: 26 additions & 22 deletions Model_T&T.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"from Utils.Grad_cam import make_gradcam_heatmap\n",
"from Utils.print_color_V2_NEW import print_Color_V2\n",
"from Utils.print_color_V1_OLD import print_Color\n",
"from Utils.Other import * # noqa: F403\n",
"from Utils.Other import * # noqa: F403\n",
"\n",
"# Other\n",
"tf.get_logger().setLevel(\"ERROR\")\n",
Expand Down Expand Up @@ -3214,10 +3214,12 @@
" layer.trainable = True\n",
"\n",
" # Combine the output of the two base models\n",
" combined = concatenate([\n",
" Dense(512, activation=\"relu\", kernel_regularizer=l2(0.01))(GlobalAveragePooling2D()(base_model1_out)),\n",
" Dense(512, activation=\"relu\", kernel_regularizer=l2(0.01))(GlobalAveragePooling2D()(base_model2_out)),\n",
" ])\n",
" combined = concatenate(\n",
" [\n",
" Dense(512, activation=\"relu\", kernel_regularizer=l2(0.01))(GlobalAveragePooling2D()(base_model1_out)),\n",
" Dense(512, activation=\"relu\", kernel_regularizer=l2(0.01))(GlobalAveragePooling2D()(base_model2_out)),\n",
" ]\n",
" )\n",
"\n",
" # adding CDL\n",
" Dense_L1 = Dense(1024, activation=\"relu\", kernel_regularizer=l2(0.02))(combined)\n",
Expand Down Expand Up @@ -9956,10 +9958,12 @@
"\n",
" old_weights, old_biases = layer.get_weights()\n",
"\n",
" layer.set_weights([\n",
" weight_initializer(shape=old_weights.shape),\n",
" bias_initializer(shape=len(old_biases)),\n",
" ])"
" layer.set_weights(\n",
" [\n",
" weight_initializer(shape=old_weights.shape),\n",
" bias_initializer(shape=len(old_biases)),\n",
" ]\n",
" )"
]
},
{
Expand Down Expand Up @@ -10356,14 +10360,14 @@
"\n",
"\n",
"# Funcs\n",
"def normalize_TO_RANGE(arr, min_val, max_val): # noqa: F811\n",
"def normalize_TO_RANGE(arr, min_val, max_val): # noqa: F811\n",
" arr = arr.astype(\"float32\")\n",
" arr = (arr - arr.min()) / (arr.max() - arr.min())\n",
" arr = arr * (max_val - min_val) + min_val\n",
" return arr\n",
"\n",
"\n",
"def Z_SCORE_normalize(arr): # noqa: F811\n",
"def Z_SCORE_normalize(arr): # noqa: F811\n",
" arr = arr.astype(\"float32\")\n",
" mean = np.mean(arr)\n",
" std_dev = np.std(arr)\n",
Expand Down Expand Up @@ -10613,8 +10617,8 @@
" advanced_mode=True,\n",
")\n",
"# warnings\n",
"P_warning(\"[RES_Train -> True].\") if RES_Train else None # noqa: F405\n",
"P_warning(\"[TerminateOnHighTemp_M -> False] GPU temperature protection is OFF\") if not TerminateOnHighTemp_M else None # noqa: F405\n",
"P_warning(\"[RES_Train -> True].\") if RES_Train else None # noqa: F405\n",
"P_warning(\"[TerminateOnHighTemp_M -> False] GPU temperature protection is OFF\") if not TerminateOnHighTemp_M else None # noqa: F405\n",
"print_Color(\"Setup Verbose END.\", [\"yellow\"])\n",
"# MAIN LOOP\n",
"try:\n",
Expand All @@ -10636,7 +10640,7 @@
" advanced_mode=True,\n",
" )\n",
" # warnings\n",
" P_warning(\"[TerminateOnHighTemp_M -> False] GPU temperature protection is OFF\") if not TerminateOnHighTemp_M else None # noqa: F405\n",
" P_warning(\"[TerminateOnHighTemp_M -> False] GPU temperature protection is OFF\") if not TerminateOnHighTemp_M else None # noqa: F405\n",
" # DP\n",
" if not AdvSubsetC:\n",
" print_Color(\"Shuffling data...\", [\"yellow\"])\n",
Expand Down Expand Up @@ -10860,7 +10864,7 @@
" # Garbage Collection (memory)\n",
" gc.collect()\n",
" tf.keras.backend.clear_session()\n",
" GPU_memUsage() # noqa: F405\n",
" GPU_memUsage() # noqa: F405\n",
" # Update TF summary text\n",
" for Key in TF_Summary_text_Dict:\n",
" TF_Summary_text_cache = f\"# @[{Key}].Data:\\n\"\n",
Expand Down Expand Up @@ -11200,10 +11204,10 @@
"from numba import cuda\n",
"\n",
"device = cuda.get_current_device()\n",
"GPU_memUsage() # noqa: F405\n",
"GPU_memUsage() # noqa: F405\n",
"print(\"Realising all memory...\")\n",
"device.reset()\n",
"GPU_memUsage() # noqa: F405\n",
"GPU_memUsage() # noqa: F405\n",
"print(\"done.\")"
]
},
Expand All @@ -11221,7 +11225,7 @@
"outputs": [],
"source": [
"# Save history\n",
"save_list(history, \"history\\\\model_history.pkl.gz\", compress=True) # noqa: F405"
"save_list(history, \"history\\\\model_history.pkl.gz\", compress=True) # noqa: F405"
]
},
{
Expand All @@ -11231,7 +11235,7 @@
"outputs": [],
"source": [
"# load history\n",
"history = load_list(\"history\\\\model_history.pkl.gz\", compressed=True) # noqa: F405"
"history = load_list(\"history\\\\model_history.pkl.gz\", compressed=True) # noqa: F405"
]
},
{
Expand Down Expand Up @@ -11705,9 +11709,9 @@
"\n",
"# Print acc\n",
"print(\"Val data acc:\")\n",
"evaluate_model_full(y_val, val_predictions) # noqa: F405\n",
"evaluate_model_full(y_val, val_predictions) # noqa: F405\n",
"print(\"Test data acc:\")\n",
"evaluate_model_full(y_test, test_predictions) # noqa: F405\n",
"evaluate_model_full(y_test, test_predictions) # noqa: F405\n",
"\n",
"# format data\n",
"val_predictions = np.argmax(val_predictions, axis=1)\n",
Expand Down Expand Up @@ -11824,7 +11828,7 @@
" plt.title(\"Number of Incorrect Predictions vs. Number of Data Points\")\n",
" plt.show()\n",
"except Exception:\n",
" P_warning(\"Failed to plot incorrect predictions vs. data points\") # noqa: F405"
" P_warning(\"Failed to plot incorrect predictions vs. data points\") # noqa: F405"
]
}
],
Expand Down
4 changes: 2 additions & 2 deletions history_vis.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from Utils.Other import * # noqa: F403
from Utils.Other import * # noqa: F403
import matplotlib.pyplot as plt
import numpy as np

# load history
history = load_list("history\\model_history.pkl.gz", compressed=True) # noqa: F405
history = load_list("history\\model_history.pkl.gz", compressed=True) # noqa: F405

# Chunk size for 3D plot
chunk_size = 6 # Change this to your desired chunk size
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
absl-py==1.4.0
adabelief-tf==0.2.1
efficientnet==1.1.1
gpu-control==1.0.0
Expand Down

0 comments on commit 17802d3

Please sign in to comment.