Skip to content

Commit

Permalink
edit setting metadate
Browse files Browse the repository at this point in the history
  • Loading branch information
Atashnezhad committed Jun 25, 2023
1 parent 4b119c4 commit def87f1
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ __pycache__/
/tests/augmented_dataset/
/tests/dataset/
/s3_dataset/
/neural_network_model/settings.json
42 changes: 29 additions & 13 deletions neural_network_model/bit_vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ def assemble_deep_net_model(self) -> tensorflow.keras.models.Sequential:
activ = "relu"

model.add(
Conv2D(32, kernel_size=(3, 3), activation=activ, input_shape=(image_size, image_size, 3))
Conv2D(
32,
kernel_size=(3, 3),
activation=activ,
input_shape=(image_size, image_size, 3),
)
)
model.add(BatchNormalization())

Expand Down Expand Up @@ -167,19 +172,25 @@ def assemble_deep_net_model_2(self) -> tensorflow.keras.models.Sequential:
dropout_dense = 0.3

model = Sequential()
model.add(Conv2D(first_filters, kernel_size, activation='relu',
input_shape=(image_size, image_size, 3)))
model.add(Conv2D(first_filters, kernel_size, activation='relu'))
model.add(
Conv2D(
first_filters,
kernel_size,
activation="relu",
input_shape=(image_size, image_size, 3),
)
)
model.add(Conv2D(first_filters, kernel_size, activation="relu"))
model.add((MaxPooling2D(pool_size=pool_size)))
model.add(Dropout(dropout_conv))

model.add(Conv2D(second_filters, kernel_size, activation='relu'))
model.add(Conv2D(second_filters, kernel_size, activation='relu'))
model.add(Conv2D(second_filters, kernel_size, activation="relu"))
model.add(Conv2D(second_filters, kernel_size, activation="relu"))
model.add((MaxPooling2D(pool_size=pool_size)))
model.add(Dropout(dropout_conv))

model.add(Conv2D(third_filters, kernel_size, activation='relu'))
model.add(Conv2D(third_filters, kernel_size, activation='relu'))
model.add(Conv2D(third_filters, kernel_size, activation="relu"))
model.add(Conv2D(third_filters, kernel_size, activation="relu"))
model.add((MaxPooling2D(pool_size=pool_size)))
model.add(Dropout(dropout_conv))

Expand All @@ -191,7 +202,6 @@ def assemble_deep_net_model_2(self) -> tensorflow.keras.models.Sequential:
self.model = model
return self.model


def compile_model(self, *args, **kwargs) -> None:
"""
This function is used to compile the model.
Expand All @@ -216,7 +226,9 @@ def plot_image_category(self, *args, **kwargs) -> None:
fig, axs = plt.subplots(nrows, ncols, figsize=fig_size)

if nrows == 1 and ncols > 1:
axs = axs.reshape((ncols,)) # Reshape axs to handle 1 row and multiple columns
axs = axs.reshape(
(ncols,)
) # Reshape axs to handle 1 row and multiple columns

for i, category in enumerate(self.categories):
category_path = self.train_test_val_dir / subdir / category
Expand Down Expand Up @@ -409,9 +421,9 @@ def predict(self, *args, **kwargs):
default_figsize = SETTING.FIGURE_SETTING.FIGURE_SIZE_IN_PRED_MODEL

# Extract details from kwargs or use default settings
num_rows = kwargs.get('num_rows', default_num_rows)
num_cols = kwargs.get('num_cols', default_num_cols)
figure_size = kwargs.get('figure_size', default_figsize)
num_rows = kwargs.get("num_rows", default_num_rows)
num_cols = kwargs.get("num_cols", default_num_cols)
figure_size = kwargs.get("figure_size", default_figsize)

for category in self.categories:
plt.figure(figsize=figure_size)
Expand Down Expand Up @@ -672,6 +684,10 @@ def return_best_model_name(

return best_model

@staticmethod
def print_deepnet_project_metadata():
SETTING.load_settings_from_json()


if __name__ == "__main__":
obj = BitVision(
Expand Down
30 changes: 28 additions & 2 deletions neural_network_model/model.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import json
import os
from pathlib import Path
from pprint import pprint
from typing import List

from dotenv import load_dotenv
from pydantic import BaseModel
from tensorflow import keras
from dotenv import load_dotenv

# Load environment variables from .env file
load_dotenv()
Expand Down Expand Up @@ -136,7 +139,7 @@ class GradCamSetting(BaseModel):


class S3BucketSetting(BaseModel):
BUCKET_NAME: str = "bitimages123"
BUCKET_NAME: str = os.getenv("BUCKET_NAME")
PARENT_FOLDER_NAME: str = "dataset"
SUBFOLDER_NAME: list = ["dataset/pdc_bit", "dataset/rollercone_bit"]
DOWNLOAD_LOCATION: str = (Path(__file__).parent / ".." / "s3_dataset").resolve()
Expand Down Expand Up @@ -192,9 +195,32 @@ class Setting(BaseModel):
EC2_SETTING: Ec2Setting = Ec2Setting()
GITHUB_SETTING: GitHubSetting = GitHubSetting()

@staticmethod
def save_settings_to_json(filename: str = "settings.json"):
def convert_paths(obj):
if isinstance(obj, (Path, tuple)):
return str(obj)
return obj

with open(filename, "w") as f:
json.dump(SETTING.dict(), f, indent=4, default=convert_paths)

@staticmethod
def load_settings_from_json(filename: str = "settings.json") -> json:
with open(filename, "r") as f:
data = json.load(f)
pprint(Setting(**data))
return Setting(**data)


SETTING = Setting()


if __name__ == "__main__":
print(SETTING.EC2_SETTING.SECURITY_GROUP_ID)
# print(SETTING.EC2_SETTING.SECURITY_GROUP_ID)
# Save the settings to a JSON file
# SETTING.save_settings_to_json("settings.json")
SETTING.load_settings_from_json("settings.json")

# Load the settings from a JSON file
# loaded_settings = load_settings_from_json("settings.json")
7 changes: 6 additions & 1 deletion neural_network_model/process_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ def _copy_images(
f"copied {len(images)} images for category {categ} to {dest_folder}"
)

@staticmethod
def print_deepnet_project_metadata():
SETTING.load_settings_from_json()


if __name__ == "__main__":
obj = Preprocessing(dataset_address=Path(__file__).parent / ".." / "dataset")
Expand All @@ -366,5 +370,6 @@ def _copy_images(
# obj.download_images(from_s3=True)

print(obj.image_dict)
obj.augment_data(number_of_images_tobe_gen=20)
obj.augment_data(number_of_images_tobe_gen=10)
obj.train_test_split()
obj.print_deepnet_project_metadata()

0 comments on commit def87f1

Please sign in to comment.