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

Migrating code to work on tensorflow 2.0 and adding running on directory #21

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

amrotork
Copy link

Migrating code to work on tensorflow 2.0 and adding running on directory

from keras.models import Model as KerasModel
from keras.layers import Input, Dense, Flatten, Conv2D, MaxPooling2D, BatchNormalization, Dropout, Reshape, Concatenate, LeakyReLU
from keras.optimizers import Adam

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useless blank line

@@ -2,7 +2,9 @@
from classifiers import *
from pipeline import *

from keras.preprocessing.image import ImageDataGenerator
import os
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import not used?

class_mode='binary',
subset='training')

# 3 - Predict
X, y = generator.next()
print('Predicted :', classifier.predict(X), '\nReal class :', y)
num_iterations = 0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this change in the predict file, I don't really want to provide a loop, this was a minimal working code to show that this uses the tf/keras framework, but there are many ways to loop over the images. So I would leave this file unchanged while letting the new script predict_on_directory do want you want to do.

@@ -0,0 +1,35 @@
########################################################################################################################
# Model
########################################################################################################################
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inaccurate comment, delete, (or change and use triple quotes to provide a documentation on the command line usage)


# 1 - Load the model and its pretrained weights
classifier = Meso4()
classifier.load('weights/Meso4_DF')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, for the purpose of a command line script, this needs parametrisation, what if your directory is forged using face-2-face.

im = load_img(f, target_size=REQUIRED_SIZE)
im_arr = np.expand_dims(img_to_array(im), axis=0)
im_arr /= 255.0
print(im_arr.shape)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure this print is vital

# Getting files
files = glob.glob(os.path.join(images_dir, "*.jpg"))
for f in files:
im = load_img(f, target_size=REQUIRED_SIZE)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better if you wrap the image loader into a ImageDataGenerator and use flow_from_directory than manually loading the images

@DariusAf
Copy link
Owner

DariusAf commented Mar 4, 2020

Thanks for your contribution and interest for this work, a command line script is indeed a good addition to this repo. I've commented several little thing on your proposed script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants