Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Areg #3

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed __init__.py
Empty file.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tensorflow.__version__ = 2.11.0
17 changes: 17 additions & 0 deletions run_pipeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from Preporcessor import Preprocessor
import tensorflow as tf
import argparse
parser = argparse.ArgumentParser()
### example path~~~\Tuned_Inseption
parser.add_argument("--data_path", type=str, help="path to testing images")
### example path~~~\data\images
parser.add_argument("--model_path", type=str, help="path to Stored Trained_Model")
args = parser.parse_args()

Pretrained_Model = tf.keras.models.load_model(args.model_path)
pepr_= Preprocessor(Path=args.data_path,Mode="Test")
Test_X,Test_Y = pepr_.fit_transform()
Scores =Pretrained_Model.evaluate(Test_X,Test_Y)

print(f"MODEL LOSS==>> {Scores[0]}")
print(f"MODEL ACCURACY==>> {Scores[1]}")
Empty file removed setup.py
Empty file.
1 change: 0 additions & 1 deletion src/Description.md

This file was deleted.

53 changes: 53 additions & 0 deletions src/Preprocessor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import tensorflow as tf
import pathlib
class Preprocessor:

def __init__(self,Path, batch_size=64, img_height=299, img_width=299, validation_rate=0.15, Mode="Train",):
"""
:param Path: Directory where your images are located
:param batch_size:
:param img_height:
:param img_width:
:param validation_rate:
:param Mode: if you want to train model and preporcess your train and validation data Initialize in Train Mode if you wont to prepare data for Test, so in test mode
"""
self.batch_size = batch_size
self.img_height = img_height
self.img_width = img_width
self.validation_rate = validation_rate
self.Mode = Mode
self.Path = pathlib.Path(Path)

def fit_transform(self):
"""
funtion return resized and labeled dataset form images Directory
if function call is in Training mode function return training and validation dataset and if in test mode return data for testing
:return:
"""
if self.Mode == "Train":
train_data_set = tf.keras.utils.image_dataset_from_directory(
self.Path,
validation_split=self.validation_rate,
subset="training",
seed=111,
image_size=(self.img_height, self.img_width),
batch_size=self.batch_size,
shuffle=True)
validation_data_set = tf.keras.utils.image_dataset_from_directory(
self.Path,
validation_split=self.validation_rate,
subset="validation",
seed=111,
image_size=(self.img_height, self.img_width),
batch_size=self.batch_size,
shuffle=True)
return train_data_set,validation_data_set
else:
Test_data_set = tf.keras.utils.image_dataset_from_directory(
self.Path,
image_size=(self.img_height, self.img_width),
batch_size=320,
shuffle=False)
x=list(Test_data_set)[0][0]
y=list(Test_data_set)[0][1]
return x,y
Empty file removed src/__init__.py
Empty file.
29 changes: 29 additions & 0 deletions src/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import tensorflow as tf
from Preporcessor import Preprocessor
Prepr_ = Preprocessor(Path="Your train_data_path ",Mode="Train")
## Loading and spltting data into train and validation sets
training_data, validation_data = Prepr_.fit_transform()
### We use GoogleNet/IncpetionV3 as our base model


Base_model = tf.keras.applications.InceptionV3(include_top=False,weights="imagenet")
Base_model.trainable=False
model = tf.keras.Sequential()
model.add(tf.keras.layers.Rescaling(scale=1./127.5, offset=-1))
model.add(Base_model)
model.add(tf.keras.layers.GlobalAvgPool2D())
## After Inception pre_ptained block we add 3 Danse layers and one Dropout layer and alos chane output layer into 10 layers Danse with softmax
## trainable patamets are ~~58000
model.add(tf.keras.layers.Dense(28,activation="relu"))
model.add(tf.keras.layers.Dense(18,activation="relu"))
model.add(tf.keras.layers.Dropout(rate=0.2))
model.add(tf.keras.layers.Dense(16,activation="relu"))
model.add(tf.keras.layers.Dense(10,activation="softmax"))
model.build(input_shape=(64,299,299,3))
optimizer = tf.keras.optimizers.Adam()
model.compile(optimizer=optimizer,loss="sparse_categorical_crossentropy",metrics=["accuracy"])

print(model.summary())

model.fit(training_data,validation_data=validation_data,epochs=10)