Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta b #188

Merged
merged 10 commits into from
Mar 14, 2024
10 changes: 4 additions & 6 deletions Archive/keras_applications_mod/models/convnext.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,10 @@ def call(self, x):

def get_config(self):
config = super().get_config()
config.update(
{
"init_values": self.init_values,
"projection_dim": self.projection_dim,
}
)
config.update({
"init_values": self.init_values,
"projection_dim": self.projection_dim,
})
return config


Expand Down
46 changes: 20 additions & 26 deletions Archive/keras_applications_mod/models/imagenet_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,11 @@ def test_preprocess_input(self):
self.assertAllClose(x, x2[..., ::-1])
self.assertNotEqual(xint.astype("float").max(), xint2.max())

@parameterized.named_parameters(
[
{"testcase_name": "mode_torch", "mode": "torch"},
{"testcase_name": "mode_tf", "mode": "tf"},
{"testcase_name": "mode_caffe", "mode": "caffe"},
]
)
@parameterized.named_parameters([
{"testcase_name": "mode_torch", "mode": "torch"},
{"testcase_name": "mode_tf", "mode": "tf"},
{"testcase_name": "mode_caffe", "mode": "caffe"},
])
def test_preprocess_input_symbolic(self, mode):
# Test image batch
x = np.random.uniform(0, 255, (2, 10, 10, 3))
Expand Down Expand Up @@ -131,13 +129,11 @@ def test_preprocess_input_symbolic(self, mode):
out2 = model2.predict(x2[np.newaxis])[0]
self.assertAllClose(out1, out2.transpose(1, 2, 0))

@parameterized.named_parameters(
[
{"testcase_name": "mode_torch", "mode": "torch"},
{"testcase_name": "mode_tf", "mode": "tf"},
{"testcase_name": "mode_caffe", "mode": "caffe"},
]
)
@parameterized.named_parameters([
{"testcase_name": "mode_torch", "mode": "torch"},
{"testcase_name": "mode_tf", "mode": "tf"},
{"testcase_name": "mode_caffe", "mode": "caffe"},
])
def test_preprocess_input_symbolic_mixed_precision(self, mode):
if not tf.__internal__.tf2.enabled():
self.skipTest("The global policy can only be tested in TensorFlow 2")
Expand All @@ -152,18 +148,16 @@ def test_preprocess_input_symbolic_mixed_precision(self, mode):
finally:
set_global_policy("float32")

@parameterized.named_parameters(
[
{
"testcase_name": "channels_last_format",
"data_format": "channels_last",
},
{
"testcase_name": "channels_first_format",
"data_format": "channels_first",
},
]
)
@parameterized.named_parameters([
{
"testcase_name": "channels_last_format",
"data_format": "channels_last",
},
{
"testcase_name": "channels_first_format",
"data_format": "channels_first",
},
])
def test_obtain_input_shape(self, data_format):
# input_shape and default_size are not identical.
with self.assertRaises(ValueError):
Expand Down
34 changes: 15 additions & 19 deletions BETA_E_Model_T&T.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@
" # ┌-----------------┬--┬-------------------┐\n",
" # │ 𝑦=2/(𝑥+1)^(𝑥+𝑉) ├OR┤ 𝑦=2/(𝑥+1)^(𝑥+1.4) │\n",
" # └-----------------┴--┴-------------------┘\n",
" print(f\"> Generating ADB[{i+1}/{ADBD}]...\")\n",
" print(f\"> Generating ADB[{i + 1}/{ADBD}]...\")\n",
" # prepare an iterators to scale images\n",
" train_iterator = train_datagen.flow(x_train, y_train, batch_size=len(x_train))\n",
"\n",
Expand Down Expand Up @@ -3214,12 +3214,10 @@
" layer.trainable = True\n",
"\n",
" # Combine the output of the two base models\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",
" 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",
"\n",
" # adding CDL\n",
" Dense_L1 = Dense(1024, activation=\"relu\", kernel_regularizer=l2(0.02))(combined)\n",
Expand Down Expand Up @@ -9958,12 +9956,10 @@
"\n",
" old_weights, old_biases = layer.get_weights()\n",
"\n",
" layer.set_weights(\n",
" [\n",
" weight_initializer(shape=old_weights.shape),\n",
" bias_initializer(shape=len(old_biases)),\n",
" ]\n",
" )"
" layer.set_weights([\n",
" weight_initializer(shape=old_weights.shape),\n",
" bias_initializer(shape=len(old_biases)),\n",
" ])"
]
},
{
Expand Down Expand Up @@ -11032,18 +11028,18 @@
" optimizer = self.model.optimizer\n",
" if hasattr(optimizer, \"lr\"):\n",
" lr = tf.keras.backend.get_value(optimizer.lr)\n",
" print(f\"\\nLearning rate for epoch {epoch+1} is {lr}\")\n",
" print(f\"\\nLearning rate for epoch {epoch + 1} is {lr}\")\n",
" if hasattr(optimizer, \"momentum\"):\n",
" momentum = tf.keras.backend.get_value(optimizer.momentum)\n",
" print(f\"Momentum for epoch {epoch+1} is {momentum}\")\n",
" print(f\"Momentum for epoch {epoch + 1} is {momentum}\")\n",
" if logs:\n",
" val_loss = logs.get(\"val_loss\")\n",
" val_acc = logs.get(\"val_accuracy\")\n",
" print(f\"Validation loss for epoch {epoch+1} is {val_loss}\")\n",
" print(f\"Validation accuracy for epoch {epoch+1} is {val_acc}\")\n",
" print(f\"Validation loss for epoch {epoch + 1} is {val_loss}\")\n",
" print(f\"Validation accuracy for epoch {epoch + 1} is {val_acc}\")\n",
"\n",
" print_Color_V2(\n",
" f\"`red`<!--------------------------------------|Epoch`yellow` [{epoch+1}]`red` End|--------------------------------------!> `green`PBE↓\",\n",
" f\"`red`<!--------------------------------------|Epoch`yellow` [{epoch + 1}]`red` End|--------------------------------------!> `green`PBE↓\",\n",
" start_char=\"`\",\n",
" end_char=\"`\",\n",
" )\n",
Expand Down Expand Up @@ -11538,7 +11534,7 @@
" plt.xlabel(\"Epoch (within chunk)\")\n",
" plt.ylabel(\"Average Value\")\n",
" plt.title(\"Average Validation Accuracy and Loss for Each Epoch Across Chunks (Ignoring First Chunk)\")\n",
" plt.xticks(epoch_indices, [f\"Epoch {i+1}\" for i in epoch_indices]) # Set x-tick labels to epoch numbers\n",
" plt.xticks(epoch_indices, [f\"Epoch {i + 1}\" for i in epoch_indices]) # Set x-tick labels to epoch numbers\n",
" plt.legend()\n",
"\n",
" plt.tight_layout()\n",
Expand Down
40 changes: 16 additions & 24 deletions Exports/V5/Python_EPO.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,18 +595,14 @@ def Debug_img_Save(img, id="DEF"):
mean_intensity_mean = reshaped_data_mean.mean(axis=-1)

# Stack the mean intensity with the reshaped data
data_with_mean_pixels = np.hstack(
[
reshaped_data_pixels,
mean_intensity_pixels.reshape(-1, 1),
]
)
data_with_mean_mean = np.hstack(
[
reshaped_data_mean,
mean_intensity_mean.reshape(-1, 1),
]
)
data_with_mean_pixels = np.hstack([
reshaped_data_pixels,
mean_intensity_pixels.reshape(-1, 1),
])
data_with_mean_mean = np.hstack([
reshaped_data_mean,
mean_intensity_mean.reshape(-1, 1),
])

# Calculate Z-scores
z_scores_pixels = np.abs(zscore(data_with_mean_pixels, axis=0))
Expand Down Expand Up @@ -855,12 +851,10 @@ def Combo_Model(freeze_layers1, freeze_layers2):
layer.trainable = True

# Combine the output of the two base models
combined = concatenate(
[
GlobalAveragePooling2D()(base_model1_out),
GlobalAveragePooling2D()(base_model2_out),
]
)
combined = concatenate([
GlobalAveragePooling2D()(base_model1_out),
GlobalAveragePooling2D()(base_model2_out),
])

# adding CDL
Dense_L1 = Dense(1024, activation="relu", kernel_regularizer=l2(0.03))(combined)
Expand Down Expand Up @@ -1153,12 +1147,10 @@ def Eff_B7_NS():

old_weights, old_biases = layer.get_weights()

layer.set_weights(
[
weight_initializer(shape=old_weights.shape),
bias_initializer(shape=len(old_biases)),
]
)
layer.set_weights([
weight_initializer(shape=old_weights.shape),
bias_initializer(shape=len(old_biases)),
])


# %% [markdown]
Expand Down
40 changes: 16 additions & 24 deletions Exports/V7/Python_EPO.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,18 +592,14 @@ def Debug_img_Save(img, id="DEF"):
mean_intensity_mean = reshaped_data_mean.mean(axis=-1)

# Stack the mean intensity with the reshaped data
data_with_mean_pixels = np.hstack(
[
reshaped_data_pixels,
mean_intensity_pixels.reshape(-1, 1),
]
)
data_with_mean_mean = np.hstack(
[
reshaped_data_mean,
mean_intensity_mean.reshape(-1, 1),
]
)
data_with_mean_pixels = np.hstack([
reshaped_data_pixels,
mean_intensity_pixels.reshape(-1, 1),
])
data_with_mean_mean = np.hstack([
reshaped_data_mean,
mean_intensity_mean.reshape(-1, 1),
])

# Calculate Z-scores
z_scores_pixels = np.abs(zscore(data_with_mean_pixels, axis=0))
Expand Down Expand Up @@ -860,12 +856,10 @@ def Combo_Model(freeze_layers1, freeze_layers2):
layer.trainable = True

# Combine the output of the two base models
combined = concatenate(
[
Dense(512, activation="relu", kernel_regularizer=l2(0.02))(GlobalAveragePooling2D()(base_model1_out)),
Dense(512, activation="relu", kernel_regularizer=l2(0.02))(GlobalAveragePooling2D()(base_model2_out)),
]
)
combined = concatenate([
Dense(512, activation="relu", kernel_regularizer=l2(0.02))(GlobalAveragePooling2D()(base_model1_out)),
Dense(512, activation="relu", kernel_regularizer=l2(0.02))(GlobalAveragePooling2D()(base_model2_out)),
])

# adding CDL
Dense_L1 = Dense(1024, activation="relu", kernel_regularizer=l2(0.03))(combined)
Expand Down Expand Up @@ -1411,12 +1405,10 @@ def load_model(filename):

old_weights, old_biases = layer.get_weights()

layer.set_weights(
[
weight_initializer(shape=old_weights.shape),
bias_initializer(shape=len(old_biases)),
]
)
layer.set_weights([
weight_initializer(shape=old_weights.shape),
bias_initializer(shape=len(old_biases)),
])


# %% [markdown]
Expand Down
25 changes: 14 additions & 11 deletions Interface/GUI/Data/GUI_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
sg.popup_auto_close("Loading GUI...", non_blocking=True, auto_close_duration=2, no_titlebar=False)
# pylib
try:
import re
# import re # noqa: F401
import time
import cv2
import json
Expand All @@ -38,14 +38,17 @@
import hashlib
import pydicom
import cpuinfo
import difflib
import inspect

# import difflib # noqa: F401
# import inspect # noqa: F401
import traceback
import subprocess
import threading
import requests
import numpy as np
from tqdm import tqdm
from time import sleep

# from time import sleep # noqa: F401
from loguru import logger
from tkinter import filedialog
from datetime import datetime
Expand All @@ -57,10 +60,10 @@
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
# Utils
from Utils.Grad_cam import make_gradcam_heatmap
from Utils.print_color_V2_NEW import print_Color_V2
from Utils.print_color_V2_NEW import print_Color_V2 # noqa: F401
from Utils.print_color_V1_OLD import print_Color
from Utils.FixedDropout import FixedDropout
from Utils.Other import *
from Utils.Other import * # noqa: F403
except (ImportError, NameError):
print("Failed to load the GUI libs")
print("detailed error message:")
Expand Down Expand Up @@ -134,9 +137,8 @@ def is_updated(self):
GUI_layout_Tab_main = [
[sg.Text("Enter the image dir:", font=(None, 10, "bold"))],
[
sg.Input(key="-INPUT_IMG_dir-"),
sg.Input(key="-INPUT_IMG_dir-", enable_events=True, size=(48, 1)),
sg.Button("Browse", key="-BUTTON_BROWSE_IMG_dir-"),
sg.Button("Ok", key="-BUTTON_OK_IMG_dir-"),
],
[sg.Text("Log:", font=(None, 10, "bold"))],
[sg.Multiline(key="-OUTPUT_ST-", size=(54, 6), autoscroll=True)],
Expand Down Expand Up @@ -538,7 +540,8 @@ def CI_liid(img_dir, Show_DICOM_INFO: bool = True) -> str:
try:
_, file_extension = os.path.splitext(img_dir)
except TypeError:
file_extension = "TEMP FILE EXTENSION"
logger.warning("CI_liid>>ERROR: Invalid file format. Please provide an image file. (Extension Extractiion Failed)")
return "ERROR: Invalid file format. Please provide an image file. (Extension Extractiion Failed)"
if file_extension.upper()[1:] not in IMG_AF:
logger.warning("CI_liid>>ERROR: Invalid file format. Please provide an image file.")
return "ERROR: Invalid file format. Please provide an image file."
Expand Down Expand Up @@ -567,7 +570,7 @@ def CI_liid(img_dir, Show_DICOM_INFO: bool = True) -> str:
GUI_layout_DICOM_Info_Window.finalize()
else:
img = Image.open(img_dir).resize((IMG_RES[1], IMG_RES[0]))
except NameError:
except (NameError, FileNotFoundError):
logger.warning("CI_liid>>ERROR: Invalid file dir. Please provide an image file.")
return "ERROR: Invalid file dir. Please provide an image file."
else:
Expand Down Expand Up @@ -777,7 +780,7 @@ def main() -> None:
GUI_window["-INPUT_IMG_dir-"].update(IMG_dir)

# Handle event for confirming the selected image directory
if event == "-BUTTON_OK_IMG_dir-":
if event == "-INPUT_IMG_dir-":
# Retrieve the image directory from the input field and update the display
IMG_dir = GUI_window["-INPUT_IMG_dir-"].get()
GUI_window["-INPUT_IMG_dir-"].update(IMG_dir)
Expand Down
Loading
Loading