Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
Atashnezhad committed Jun 25, 2023
1 parent 18a6d63 commit 3c6e3c4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
15 changes: 13 additions & 2 deletions neural_network_model/bit_vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,22 @@
import tensorflow as tf
from keras import Sequential
from keras.callbacks import ModelCheckpoint
from keras.layers import BatchNormalization, Conv2D, Dense, Dropout, Flatten, MaxPooling2D
from keras.layers import (
BatchNormalization,
Conv2D,
Dense,
Dropout,
Flatten,
MaxPooling2D,
)
from tensorflow import keras
from tensorflow.keras.applications.resnet50 import decode_predictions, preprocess_input
from tensorflow.keras.preprocessing import image
from tensorflow.keras.preprocessing.image import ImageDataGenerator, img_to_array, load_img
from tensorflow.keras.preprocessing.image import (
ImageDataGenerator,
img_to_array,
load_img,
)

from neural_network_model.model import SETTING

Expand Down
10 changes: 7 additions & 3 deletions neural_network_model/process_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

from bing_image_downloader import downloader
from tensorflow.keras.preprocessing import image
from tensorflow.keras.preprocessing.image import ImageDataGenerator, img_to_array, load_img
from tensorflow.keras.preprocessing.image import (
ImageDataGenerator,
img_to_array,
load_img,
)
from tqdm import tqdm

from neural_network_model.model import SETTING
Expand Down Expand Up @@ -289,8 +293,8 @@ def _populated_augmented_images_into_train_test_val_dirs(self, *arges, **kwargs)

# Create three new lists containing 70%, 20%, and 10% of the original list
train_list = selected_items[:num_train]
test_list = selected_items[num_train: num_train + num_test]
val_list = selected_items[num_train + num_test:]
test_list = selected_items[num_train : num_train + num_test] # noqa: E203
val_list = selected_items[num_train + num_test :] # noqa: E203
# copy the images from the dataset_augmented pdc_bit folder to the train, test and validation folders
self._copy_images(
train_list,
Expand Down
18 changes: 9 additions & 9 deletions neural_network_model/script_run_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


def main():

parent_dir = Path(__file__).resolve().parent.parent
# download the images
obj = Preprocessing(dataset_address=parent_dir / "dataset")
Expand All @@ -17,7 +16,7 @@ def main():
)
obj.train_test_split(
augmented_data_address=parent_dir / "dataset_augmented",
train_test_val_split_dir_address=parent_dir / "dataset_train_test_val"
train_test_val_split_dir_address=parent_dir / "dataset_train_test_val",
)

obj = BitVision(train_test_val_dir=parent_dir / "dataset_train_test_val")
Expand All @@ -28,9 +27,7 @@ def main():
#
model_name = "model_epoch_{epoch:02d}_loss_{loss:.2f}_acc_{accuracy:.2f}_val_acc_{val_accuracy:.2f}_.h5"
obj.train_model(
epochs=8,
model_save_address=parent_dir / "deep_model",
model_name=model_name
epochs=8, model_save_address=parent_dir / "deep_model", model_name=model_name
)
obj.plot_history(fig_folder_address=parent_dir / "figures")

Expand All @@ -39,7 +36,7 @@ def main():
obj.predict(
fig_save_address=parent_dir / "figures",
model_path=parent_dir / "deep_model" / best_model,
test_folder_address=parent_dir / "dataset_train_test_val" / "test"
test_folder_address=parent_dir / "dataset_train_test_val" / "test",
)

# find list of images in the parent_dir / "dataset_train_test_val" / "test" / "pdc_bit"
Expand All @@ -49,9 +46,12 @@ def main():
obj.grad_cam_viz(
model_path=parent_dir / "deep_model" / best_model,
fig_to_save_address=parent_dir / "figures",
img_to_be_applied_path=parent_dir / "dataset_train_test_val" / "test" / "pdc_bit" / list_of_images[
0],
output_gradcam_fig_name="test.png"
img_to_be_applied_path=parent_dir
/ "dataset_train_test_val"
/ "test"
/ "pdc_bit"
/ list_of_images[0],
output_gradcam_fig_name="test.png",
)


Expand Down
6 changes: 4 additions & 2 deletions tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@


def test_run_all():
script_path = Path(__file__).parent / ".." / "neural_network_model" / "script_run_all.py"
os.system(f'python {script_path}')
script_path = (
Path(__file__).parent / ".." / "neural_network_model" / "script_run_all.py"
)
os.system(f"python {script_path}")
assert True

0 comments on commit 3c6e3c4

Please sign in to comment.