Skip to content

Commit

Permalink
Merge pull request #245 from Aydinhamedi/Alpha-b
Browse files Browse the repository at this point in the history
Alpha b
  • Loading branch information
Aydinhamedi committed Apr 29, 2024
2 parents eb60d17 + 40d926d commit 3b5cbd7
Show file tree
Hide file tree
Showing 8 changed files with 1,562 additions and 2,673 deletions.
61 changes: 29 additions & 32 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,97 +1,94 @@
# Exclude Visual Studio Code project settings

/.vscode

# Exclude Visual Studio project settings

/.vs

# Exclude database files

/Database

# Exclude downloaded files

/download

# Exclude model files

/models

# Exclude Python cache files

__pycache__/

# Ignore all files in the logs/fit directory

logs/fit/*

# Ignore all files in the Samples directory

Samples/*

# Do not ignore directories in logs/fit that end with _STR

!logs/fit/*_STR/

# Do not ignore directories in Samples that end with _STR

!Samples/*_STR/

# Do not ignore .gz files in directories in Samples that end with _STR

!Samples/*_STR.gz

# Exclude specific model weight files

/PAI_model_weights.h5
/PAI_model_weights_BL.h5
/PAI_model_T.h5
/PAI_model_T_BL.h5

# Exclude cache files

/cache

# Exclude build artifacts

/Build

# Exclude validation files

/validation

# Exclude project file for Pneumonia AI

/Pneumonia AI.pyproj

# Exclude specific model file used in the CLI interface

/Interface/CLI/Data/PAI_model.h5

# Exclude temporary files

/TEMP.txt
/freearc1.tmp

# Exclude logs and dataset files in the CLI interface

/Interface/CLI/Data/logs
/Interface/CLI/Data/dataset.npy

# Exclude temporary Python version file in the CLI interface

/Interface/CLI/Data/Python Ver.tmp

# Exclude specific model file used in the GUI interface

/Interface/GUI/Data/PAI_model.h5

# Exclude temporary Python version file in the GUI interface

/Interface/GUI/Data/Python Ver.tmp

# Virtual environment directories

/venv_2
/venv

# Python Embed directory

/Interface/CLI/Data/Python Embed 3.10.11
/Interface/CLI/Data/Use_Python_Embed.tmp
/Interface/CLI/Python.Embed.3.10.11.exe

# GUI development file
/Interface/GUI/GUI_DEV.cmd

# Exclude logs in GUI interface

/Interface/GUI/Data/logs

# Other excluded files

/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
/Test.md
Expand All @@ -100,9 +97,9 @@ Samples/*
/ruff_format_results.txt
/Load_Backup.py

# Exclude backup load

/Backup_*_COPY.ipynb

# Temp
/history/Archive

/history/Archive
/Test_ENV_G.ipynb
18 changes: 7 additions & 11 deletions BETA_E_Model_T&T.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4935,17 +4935,10 @@
],
"source": [
"# Create a simple transformer model\n",
"model = vit.vit_b32(\n",
" image_size=224,\n",
" activation='sigmoid',\n",
" pretrained=True,\n",
" include_top=True,\n",
" pretrained_top=False,\n",
" classes=2\n",
")\n",
"model = vit.vit_b32(image_size=224, activation=\"sigmoid\", pretrained=True, include_top=True, pretrained_top=False, classes=2)\n",
"# model compile + summary\n",
"opt = SGD(learning_rate=0.01, momentum=0.9) # noqa: F405\n",
"model.compile(loss='categorical_crossentropy', optimizer=opt, metrics=['accuracy'])\n",
"opt = SGD(learning_rate=0.01, momentum=0.9) # noqa: F405\n",
"model.compile(loss=\"categorical_crossentropy\", optimizer=opt, metrics=[\"accuracy\"])\n",
"model.summary()"
]
},
Expand Down Expand Up @@ -9522,7 +9515,10 @@
"\n",
" print_Color(\"- Augmenting Image Data...\", [\"yellow\"])\n",
" train_SUB_augmented_images = train_SUB_datagen.flow(\n",
" x_SUB_train * 255, y_SUB_train, shuffle=False, batch_size=len(x_SUB_train),\n",
" x_SUB_train * 255,\n",
" y_SUB_train,\n",
" shuffle=False,\n",
" batch_size=len(x_SUB_train),\n",
" ).next()\n",
" print_Color(\"- Normalizing Image Data...\", [\"yellow\"])\n",
" x_SUB_train = normalize_TO_RANGE(train_SUB_augmented_images[0], 0, 255)\n",
Expand Down
204 changes: 204 additions & 0 deletions Build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
# Pylib
import re
import os
import sys
import uuid
import shutil
import pprint
import py_compile
import subprocess as subP

# prep
pprint = pprint.PrettyPrinter(indent=4)


# Other funcs
def should_ignore(path, ignore_list):
"""Checks if a path should be ignored based on the provided ignore patterns.
Args:
path (str): The path to check.
ignore_list (List[str]): The list of ignore patterns.
Returns:
bool: True if the path should be ignored, False otherwise.
"""
for pattern in ignore_list:
if re.search(pattern, path):
return True
return False


def copy_with_ignore(src, dst, ignore_list):
"""Recursively copies files from src to dst, ignoring files that match the ignore patterns.
Args:
src: Source directory path.
dst: Destination directory path.
ignore_list: List of glob patterns to ignore when copying.
"""
if not os.path.exists(dst):
os.makedirs(dst)
for item in os.listdir(src):
s = os.path.join(src, item)
d = os.path.join(dst, item)
if os.path.isdir(s):
copy_with_ignore(s, d, ignore_list)
else:
if not should_ignore(s, ignore_list):
shutil.copy2(s, d)


def move_folders(src_dir, dest_dir):
"""Moves all subdirectories from a source directory to a destination directory.
Args:
src_dir (str): The source directory path.
dest_dir (str): The destination directory path.
"""
# Check if destination directory exists, if not create it
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)

# List all directories in the source directory
for dir_name in os.listdir(src_dir):
full_dir_name = os.path.join(src_dir, dir_name)

# Check if it's a directory and not the destination directory
if os.path.isdir(full_dir_name) and full_dir_name != dest_dir:
# Move the directory to the destination directory
shutil.move(full_dir_name, dest_dir)


def Compile_python(path):
"""Compiles python"""
# Iterate over all files in the directory
for root, dirs, files in os.walk(path):
for filename in files:
# Check if the file is a Python script
if filename.endswith(".py"):
# Compile the Python script to a .pyc file
try:
py_compile.compile(os.path.join(root, filename), optimize=2)
except py_compile.PyCompileError as e:
print(f"Failed to compile {filename}: {e}")
continue

# Define the source file and destination file
src = os.path.join(
root, "__pycache__", filename[:-3] + f".cpython-{sys.version_info.major}{sys.version_info.minor}.opt-2.pyc"
)
dst = os.path.join(root, filename[:-3] + ".pyc")

# Check if the .pyc file exists
if not os.path.exists(src):
print(src)
print(f"Failed to find .pyc file for {filename}")
continue

# Move the .pyc file
try:
shutil.move(src, dst)
except shutil.Error as e:
print(f"Failed to move .pyc file for {filename}: {e}")
continue

# Delete the original .py file
try:
os.remove(os.path.join(root, filename))
except OSError as e:
print(f"Failed to delete .py file for {filename}: {e}")


# Build funcs
def Build_Main():
# Init
RUN_Path_dict = {
"Model info": ("python", "Make_model_info.py"),
"Ruff (Check + Format)": ("Ruff_Auto.cmd"),
"Sync code": ("Update_Code.cmd"),
"Gen Requirements": ("Create_requirements.cmd"),
}
Sync_Utils = False
# Starting...
print("<Build Main> --> Starting...")
# Proc Auto
print("<Build Main> <Proc Auto - Init> --> Run dict:")
for key, value in RUN_Path_dict.items():
print(f" -- Key: {key}, Value: {value}")
print("<Build Main> <Proc Auto - Start> --> Run dict:")
for process in RUN_Path_dict:
print(f"<Build Main> <Proc Auto> --> Running [{process}]...")
# Run
subP.run(RUN_Path_dict[process], shell=False)
# End
print(f"<Build Main> <Proc Auto> --> [{process}] Done.")
# Sync Utils
if Sync_Utils:
print("<Build Main> <Sync Utils> --> Starting...")
Main_utils_path = "Utils"
utils_destinations = ["Interface\\GUI\\Data\\Utils", "Interface\\CLI\\Data\\Utils"]
for utils_destination in utils_destinations:
print(f"<Build Main> <Sync Utils> --> copying utils from {Main_utils_path} to {utils_destination}...")
shutil.copytree(Main_utils_path, utils_destination, dirs_exist_ok=True)
print("<Build Main> <Sync Utils> --> Done.")
# Copy CLI / GUI Build
print("<Build Main> <(CLI / GUI) Build> --> Starting...")
Ignore_list = [
r".*\.h5$",
r".*\.pyc$",
r".*\.tmp$",
r".*\\*logs\\.*$",
r".*\\__pycache__$",
r".*\\GUI_Build\.py$",
r".*\\GUI_DEV\.cmd$",
r".*\\Data\\Gen_lib\.cmd$",
r".*\\model_info\.json$",
]
# CLI
CLI_dir = "Interface\\CLI"
CLI_Build_folder = "Build\\Github\\Releases\\Other\\Interface\\CLI"
CLI_Archive_dir = "Build\\Github\\Releases\\Other\\Interface\\CLI\\Archive"
CLI_Build_dir = f"Build\\Github\\Releases\\Other\\Interface\\CLI\\{uuid.uuid4()}"
print("<Build Main> <(CLI / GUI) Build> --> CLI Build...")
print(f" -- Build dir: {CLI_Build_dir}")
print(" -- Archiving old builds...")
move_folders(CLI_Build_folder, CLI_Archive_dir)
print(" -- Copying new build...")
copy_with_ignore(CLI_dir, CLI_Build_dir, Ignore_list)
print("<Build Main> <(CLI / GUI) Build> --> CLI Build Done.")
# GUI
GUI_dir = "Interface\\GUI"
GUI_Build_folder = "Build\\Github\\Releases\\Other\\Interface\\GUI"
GUI_Archive_dir = "Build\\Github\\Releases\\Other\\Interface\\GUI\\Archive"
GUI_Build_dir = f"Build\\Github\\Releases\\Other\\Interface\\GUI\\{uuid.uuid4()}"
print("<Build Main> <(CLI / GUI) Build> --> GUI Build...")
print(f" -- Build dir: {GUI_Build_dir}")
print(" -- Archiving old builds...")
move_folders(GUI_Build_folder, GUI_Archive_dir)
print(" -- Copying new build...")
copy_with_ignore(GUI_dir, GUI_Build_dir, Ignore_list)
if input("<Build Main> <(CLI / GUI) Build> --> [Beta] Compile GUI? (y/n): ") == "y":
print("<Build Main> <(CLI / GUI) Build> --> Compiling GUI...")
Compile_python(GUI_Build_dir)
print("<Build Main> <(CLI / GUI) Build> --> Compiling GUI Done.")
print("<Build Main> <(CLI / GUI) Build> --> GUI Build Done.")
print("<Build Main> <(CLI / GUI) Build> --> Done.")
# End.
print("<Build Main> --> End.")


# Main
def main():
print("Starting the build... \n")
Build_Main()


if __name__ == "__main__":
try:
main()
except Exception:
print("\nError: ")
raise
else:
print("\nBuild complete.")
6 changes: 3 additions & 3 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
cff-version: 1.2.0
title: PyTorch-Project-Template
message: "A Simple Template For A PyTorch Classification Project \U0001F604"
title: Pneumonia-Detection-Ai
message: "This project uses a deep learning model built with the TensorFlow Library to detect pneumonia in X-ray images. The model architecture is based on the EfficientNetB7 model, which has achieved an accuracy of approximately 97.12% (97.11538%) on our test data. This high accuracy rate is one of the strengths of our AI model."
type: software
authors:
- email: [email protected]
given-names: Aydin
family-names: Hamedi
repository-code: 'https://github.com/Aydinhamedi/PyTorch-Project-Template'
repository-code: 'https://github.com/Aydinhamedi/Pneumonia-Detection-Ai'
license: MIT
Loading

0 comments on commit 3b5cbd7

Please sign in to comment.