-
Notifications
You must be signed in to change notification settings - Fork 116
Migrating code to work on tensorflow 2.0 and adding running on directory #21
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,9 @@ | |
| from classifiers import * | ||
| from pipeline import * | ||
|
|
||
| from keras.preprocessing.image import ImageDataGenerator | ||
| import os | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. import not used? |
||
|
|
||
| from tensorflow.keras.preprocessing.image import ImageDataGenerator | ||
|
|
||
| # 1 - Load the model and its pretrained weights | ||
| classifier = Meso4() | ||
|
|
@@ -17,15 +19,19 @@ | |
| 'test_images', | ||
| target_size=(256, 256), | ||
| batch_size=1, | ||
| shuffle=False, | ||
| class_mode='binary', | ||
| subset='training') | ||
|
|
||
| # 3 - Predict | ||
| X, y = generator.next() | ||
| print('Predicted :', classifier.predict(X), '\nReal class :', y) | ||
| num_iterations = 0 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| for X, y in generator: | ||
| print('Predicted :', classifier.predict(X), '\nReal class :', y) | ||
| num_iterations += 1 | ||
| if num_iterations >= 4: | ||
| break | ||
|
|
||
| # 4 - Prediction for a video dataset | ||
|
|
||
| classifier.load('weights/Meso4_F2F') | ||
|
|
||
| predictions = compute_accuracy(classifier, 'test_videos') | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| ######################################################################################################################## | ||
| # Model | ||
| ######################################################################################################################## | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
|
|
||
| import numpy as np | ||
| from classifiers import * | ||
| from pipeline import * | ||
|
|
||
| import os | ||
| import glob | ||
| import sys | ||
| from tensorflow.keras.preprocessing.image import load_img, img_to_array | ||
|
|
||
| REQUIRED_SIZE = (256, 256) | ||
|
|
||
| if __name__ == "__main__": | ||
| images_dir = sys.argv[1] | ||
|
|
||
| if not os.path.isdir(images_dir): | ||
| print("## Directory provided {} doesn't exist.".format(images_dir)) | ||
| exit() | ||
|
|
||
| # 1 - Load the model and its pretrained weights | ||
| classifier = Meso4() | ||
| classifier.load('weights/Meso4_DF') | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
| # Getting files | ||
| files = glob.glob(os.path.join(images_dir, "*.jpg")) | ||
| for f in files: | ||
| im = load_img(f, target_size=REQUIRED_SIZE) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's better if you wrap the image loader into a |
||
| im_arr = np.expand_dims(img_to_array(im), axis=0) | ||
| im_arr /= 255.0 | ||
| print(im_arr.shape) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure this print is vital |
||
| pred = classifier.predict(im_arr) | ||
| print("## Image {} is classified as {}".format(f, pred)) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useless blank line