Skip to content

Commit

Permalink
Merge pull request #170 from Aydinhamedi/Beta-b
Browse files Browse the repository at this point in the history
Beta b
  • Loading branch information
Aydinhamedi authored Feb 29, 2024
2 parents 06cdd2d + fd0456a commit 7c4dc70
Show file tree
Hide file tree
Showing 47 changed files with 17,115 additions and 10,605 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: 'Dependency Review'
uses: actions/dependency-review-action@v3
uses: actions/dependency-review-action@v4
4 changes: 2 additions & 2 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python-app_Alpha-b.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python-app_Beta-b.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
Expand Down
14 changes: 9 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,12 @@ Samples/*
/Interface/GUI/Data/logs

# Other
/Test_ENV_G.py
/scc.exe
/SCC_Auto.cmd
/Microsoft.PowerShell_profile_Nvidia_smi.ps1
/Data/image_SUB_generator.pkl
/Test_ENV_G.py
/scc.exe
/SCC_Auto.cmd
/Microsoft.PowerShell_profile_Nvidia_smi.ps1
/Data/image_SUB_generator.pkl
/GPU_Info.txt
/Build.py
/env
/Temp
8,990 changes: 8,552 additions & 438 deletions BETA_E_Model_T&T.ipynb

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions Create_requirements.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
@echo off
del requirements.txt >nul 2>&1
pigar -l INFO generate
del requirements.txt >nul 2>&1
echo Y | pigar -l ERROR generate

rem Use PowerShell to remove the first line of requirements.txt and save to a temporary file
powershell -Command "Get-Content requirements.txt | Select-Object -Skip 2 | Set-Content requirements_temp.txt"

rem Replace the original file with the modified temporary file
move /Y requirements_temp.txt requirements.txt >nul
Binary file added Data/image_SUB_generator.pkl
Binary file not shown.
19 changes: 19 additions & 0 deletions Interface/CLI/Data/Utils/FixedDropout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from tensorflow.keras import layers, backend

class FixedDropout(layers.Dropout):
def _get_noise_shape(self, inputs):
if self.noise_shape is None:
return self.noise_shape

symbolic_shape = backend.shape(inputs)
noise_shape = [symbolic_shape[axis] if shape is None else shape
for axis, shape in enumerate(self.noise_shape)]
return tuple(noise_shape)

def get_config(self):
config = super().get_config()
return config

@classmethod
def from_config(cls, config):
return cls(**config)
103 changes: 94 additions & 9 deletions Interface/CLI/Data/Utils/Other.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,45 @@
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score
from Utils.print_color_V2_NEW import print_Color_V2
from Utils.print_color_V1_OLD import print_Color
from tabulate import tabulate
from numba import cuda
import numpy as np
import pickle
import gzip

def GPU_memUsage(Print=True):
"""Prints GPU memory usage for each GPU.
Args:
Print (bool): Whether to print the memory usage.
If True, prints the memory usage.
If False, returns the free and total memory as a tuple.
Returns:
If Print is False, returns a tuple (free, total) with the free
and total memory in bytes for the GPU.
"""
gpus = cuda.gpus.lst
for gpu in gpus:
with gpu:
meminfo = cuda.current_context().get_memory_info()
if Print:
print_Color(
f'~*(GPU-MEM)~*--{gpu}--[free: {meminfo.free / (1024 ** 3):.2f}GB, used: {meminfo.total / (1024 ** 3) - meminfo.free / (1024 ** 3):.2f}GB, total, {meminfo.total / (1024 ** 3):.2f}GB]',
['green', 'cyan'],
advanced_mode=True)
else:
return meminfo.free, meminfo.total

def save_list(history, filename, compress=True):
# Saves the given history list to the specified filename.
# If compress is True, the file will be gzip compressed.
# Otherwise it will be saved as a normal pickle file.
"""Saves a list to a file.
Args:
history: The list to save.
filename: The file to save the list to.
compress: Whether to gzip compress the file. Default is True.
"""
if compress:
with gzip.open(filename, 'wb') as f:
pickle.dump(history, f)
Expand All @@ -16,17 +49,69 @@ def save_list(history, filename, compress=True):


def load_list(filename, compressed=True):
# Loads a pickled object from a file.
# If compressed=True, it will load from a gzip compressed file.
# Otherwise loads from a regular file.
"""Loads a list from a file.
Args:
filename: The file to load from.
compressed: Whether the file is gzip compressed. Default is True.
Returns:
The loaded list from the file.
"""
if compressed:
with gzip.open(filename, 'rb') as f:
return pickle.load(f)
else:
with open(filename, 'rb') as f:
return pickle.load(f)


def P_warning(msg):
# Prints a warning message with color formatting.
# msg: The message to print as a warning.
"""Prints a warning message to the console.
Args:
msg (str): The warning message to print.
"""
print_Color_V2(f'<light_red>Warning: <yellow>{msg}')


def evaluate_model_full(y_test, model_pred, model=None, x_test=None):
"""Evaluates a machine learning model on a test set.
Args:
x_test: Test set features.
y_test: Test set labels.
model_pred: Model predictions.
model: The model object.
Returns:
None. Prints a table with accuracy, precision, recall and
F1 score.
"""
# Get the model predictions
if model_pred is None:
y_pred = model.predict(x_test)
else:
y_pred = model_pred

# Convert one-hot encoded predictions and labels to label encoded form
y_pred_bin = np.argmax(y_pred, axis=1)
y_test_bin = np.argmax(y_test, axis=1)

# Calculate normal metrics
accuracy = accuracy_score(y_test_bin, y_pred_bin)

# Calculate weighted metrics
weighted_precision = precision_score(
y_test_bin, y_pred_bin, average='macro')
weighted_f1 = f1_score(y_test_bin, y_pred_bin, average='macro')
weighted_recall = recall_score(y_test_bin, y_pred_bin, average='macro')

# Prepare data for the table
metrics = [["Accuracy", round(accuracy * 100, 6)],
["Precision", round(weighted_precision * 100, 6)],
["F1 Score", round(weighted_f1 * 100, 6)],
["Recall", round(weighted_recall * 100, 6)]]

# Print the table
print(tabulate(metrics, headers=["Metric", "Value"], tablefmt="pretty"))

16 changes: 13 additions & 3 deletions Interface/CLI/Data/Utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@

## one_cycle_lr and lr_find (by 'benihime91')
- ### github repo used: [one_cycle_lr-tensorflow](https://github.com/benihime91/one_cycle_lr-tensorflow/tree/master)
- ### doc link: [1_README.md](docs\1_README.md)
- ### doc link: [1_README.md](docs/1_README.md)

## Python-color-print-V2 and Python-color-print (by Me)
- ### github repo used(Python-color-print-V2): [Python-color-print-V2](https://github.com/Aydinhamedi/Python-color-print-V2)
- ### doc link: [2_README.md](docs\2_README.md)
- ### doc link: [2_README.md](docs/2_README.md)
- ### github repo used(Python-color-print): [Python-color-print](https://github.com/Aydinhamedi/Python-color-print)
- ### doc link: [3_README.md](docs\3_README.md)
- ### doc link: [3_README.md](docs/3_README.md)

## Grad_cam (by GPT-4 😁)

## Other.py (by Me)

## FixedDropout.py (by Me)
For EfficientNet model. Example:
```python
from Utils.FixedDropout import FixedDropout
from keras.models import load_model

# Load the model
model = load_model('PAI_model_T.h5', custom_objects={'FixedDropout': FixedDropout})
```
Loading

0 comments on commit 7c4dc70

Please sign in to comment.