Skip to content

Commit

Permalink
edit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Atashnezhad committed Jun 22, 2023
1 parent 47bd5a0 commit d740d32
Showing 1 changed file with 24 additions and 53 deletions.
77 changes: 24 additions & 53 deletions tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,86 +9,57 @@
main_dir = current_dir.parent
# Add the main directory to the Python path
sys.path.append(str(main_dir))
# skip this test TODO: fix this test later
import pytest

import pytest
from neural_network_model.bit_vision import BitVision
from neural_network_model.process_data import Preprocessing


@pytest.mark.skip(reason="no way of currently testing this")
# @pytest.mark.skip(reason="no way of currently testing this")
def test_run():
# check if a dir name test_resources exists if not create one
if not os.path.exists(Path(__file__).parent / "test_resources"):
os.mkdir(Path(__file__).parent / "test_resources")

# download the images
obj = Preprocessing(
dataset_address=Path(__file__).parent / "test_resources" / "dataset"
)
obj = Preprocessing(dataset_address=Path(__file__).parent / "dataset")
obj.download_images(limit=10)
print(obj.image_dict)
obj.augment_data(
number_of_images_tobe_gen=10,
augment_data_address=Path(__file__).parent
/ "test_resources"
/ "augmented_dataset",
augment_data_address=Path(__file__).parent / "augmented_dataset"
)
obj.train_test_split(
augmented_data_address=Path(__file__).parent
/ "test_resources"
/ "augmented_dataset",
train_test_val_split_dir_address=Path(__file__).parent
/ "test_resources"
/ "dataset_train_test_val",
augmented_data_address=Path(__file__).parent / "augmented_dataset",
train_test_val_split_dir_address=Path(__file__).parent / "dataset_train_test_val"
)

obj = BitVision(
train_test_val_dir=Path(__file__).parent
/ "test_resources"
/ "dataset_train_test_val"
)
obj = BitVision(train_test_val_dir=Path(__file__).parent / "dataset_train_test_val")
print(obj.categories)
print(obj.data_details)
obj.plot_image_category()
obj.compile_model()

#
model_name = "model_epoch_{epoch:02d}_loss_{loss:.2f}_acc_{accuracy:.2f}_val_acc_{val_accuracy:.2f}_.h5"
obj.train_model(
model_save_address=Path(__file__).parent / "test_resources" / "deep_model",
model_name=model_name,
epochs=10,
)
obj.plot_history(
fig_folder_address=Path(__file__).parent / "test_resources" / "figures"
epochs=8,
model_save_address=Path(__file__).parent / "deep_model",
model_name=model_name
)
obj.plot_history(fig_folder_address=Path(__file__).parent / "figures")

best_model = obj.return_best_model_name(directory="deep_model")

obj.predict(
fig_save_address=Path(__file__).parent / "test_resources" / "figures",
model_path=Path(__file__).parent / "test_resources" / "deep_model" / model_name,
test_folder_address=Path(__file__).parent
/ "test_resources"
/ "dataset_train_test_val"
/ "test",
fig_save_address=Path(__file__).parent / "figures",
model_path=Path(__file__).parent / "deep_model" / best_model,
test_folder_address=Path(__file__).parent / "dataset_train_test_val" / "test"
)

# find list of images in the Path(__file__).parent / "dataset_train_test_val" / "test" / "pdc_bit"
directory_path = (
Path(__file__).parent
/ "test_resources"
/ "dataset_train_test_val"
/ "test"
/ "pdc_bit"
)
directory_path = Path(__file__).parent / "dataset_train_test_val" / "test" / "pdc_bit"
list_of_images = [str(x) for x in directory_path.glob("*.jpeg")]

obj.grad_cam_viz(
model_path=Path(__file__).parent / "test_resources" / "deep_model" / model_name,
fig_to_save_address=Path(__file__).parent / "test_resources" / "figures",
img_to_be_applied_path=Path(__file__).parent
/ "test_resources"
/ "dataset_train_test_val"
/ "test"
/ "pdc_bit"
/ list_of_images[0],
output_gradcam_fig_name="gradcam.png",
model_path=Path(__file__).parent / "deep_model" / best_model,
fig_to_save_address=Path(__file__).parent / "figures",
img_to_be_applied_path=Path(__file__).parent / "dataset_train_test_val" / "test" / "pdc_bit" / list_of_images[
0],
output_gradcam_fig_name="gradcam.png"
)

0 comments on commit d740d32

Please sign in to comment.