Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

All #37

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

All #37

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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ saved_models/weights.best.from_scratch.hdf5
saved_models/weights.best.vgg16.hdf5
.ipynb_checkpoints/
bottleneck_features/DogVGG16Data.npz
*.h5
*.tflite

8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/dog-project.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added AccVal_acc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added LossVal_loss.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added __MACOSX/._lfw
Binary file not shown.
Binary file added bottleneck_features/DogResnet50Data.npz
Binary file not shown.
21 changes: 21 additions & 0 deletions check_images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from struct import unpack
from tqdm import tqdm
import os
import glob

fileList = glob.glob('./dogImages/*/*/*.*')

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

for i, image_name in enumerate(fileList):
print(i, image_name)

with tf.Graph().as_default():
image_contents = tf.read_file(image_name)
image = tf.image.decode_jpeg(image_contents, channels=3)
#
with tf.Session() as sess:
#sess.run(init_op)
sess.run(tf.global_variables_initializer())
tmp = sess.run(image)
933 changes: 463 additions & 470 deletions dog_app.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion extract_bottleneck_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def extract_VGG19(tensor):
return VGG19(weights='imagenet', include_top=False).predict(preprocess_input(tensor))

def extract_Resnet50(tensor):
from keras.applications.resnet50 import ResNet50, preprocess_input
from keras.applications.resnet import ResNet50, preprocess_input
return ResNet50(weights='imagenet', include_top=False).predict(preprocess_input(tensor))

def extract_Xception(tensor):
Expand Down
Binary file added images/asd.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/bb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/cat.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/db.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/dbd.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/dbdb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/dp.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/hhh.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/qqq.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rr.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rt.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/st.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/tt.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
101 changes: 101 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
absl-py==0.15.0
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
astunparse==1.6.3
attrs==21.4.0
backcall==0.2.0
bleach==4.1.0
cachetools==4.2.4
certifi==2020.6.20
cffi==1.15.0
charset-normalizer==2.0.10
colorama==0.4.4
cycler==0.11.0
debugpy==1.5.1
decorator==5.1.0
defusedxml==0.7.1
entrypoints==0.3
flatbuffers==1.12
fonttools==4.28.5
gast==0.3.3
google-auth==2.3.3
google-auth-oauthlib==0.4.6
google-pasta==0.2.0
grpcio==1.32.0
h5py==2.10.0
idna==3.3
importlib-metadata==4.10.0
importlib-resources==5.4.0
ipykernel==6.6.1
ipython==7.31.0
ipython-genutils==0.2.0
jedi==0.18.1
Jinja2==3.0.3
joblib==1.1.0
jsonschema==4.3.3
jupyter-client==7.1.0
jupyter-core==4.9.1
jupyterlab-pygments==0.1.2
Keras-Preprocessing==1.1.2
kiwisolver==1.3.2
Markdown==3.3.6
MarkupSafe==2.0.1
matplotlib==3.5.1
matplotlib-inline==0.1.3
mistune==0.8.4
nbclient==0.5.9
nbconvert==6.4.0
nbformat==5.1.3
nest-asyncio==1.5.4
notebook==6.4.6
numpy==1.19.5
oauthlib==3.1.1
opt-einsum==3.3.0
packaging==21.3
pandas==1.3.5
pandocfilters==1.5.0
parso==0.8.3
pickleshare==0.7.5
Pillow==9.0.0
prometheus-client==0.12.0
prompt-toolkit==3.0.24
protobuf==3.19.1
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.21
Pygments==2.11.2
pyparsing==3.0.6
pyrsistent==0.18.0
python-dateutil==2.8.2
pytz==2021.3
pywin32==303
pywinpty==1.1.6
pyzmq==22.3.0
requests==2.27.1
requests-oauthlib==1.3.0
rsa==4.8
scikit-learn==1.0.2
scipy==1.7.3
Send2Trash==1.8.0
six==1.15.0
sklearn==0.0
tensorboard==2.7.0
tensorboard-data-server==0.6.1
tensorboard-plugin-wit==1.8.1
tensorflow-estimator==2.4.0
tensorflow-gpu==2.4.0
termcolor==1.1.0
terminado==0.12.1
testpath==0.5.0
threadpoolctl==3.0.0
tornado==6.1
tqdm==4.62.3
traitlets==5.1.1
typing-extensions==3.7.4.3
urllib3==1.26.7
wcwidth==0.2.5
webencodings==0.5.1
Werkzeug==2.0.2
wincertstore==0.2
wrapt==1.12.1
zipp==3.7.0
15 changes: 15 additions & 0 deletions saved_models/convert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from keras.models import load_model
import tensorflow as tf

model = load_model("catdog.h5")


converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()

print("model converted")

# Save the model.
with open('model.tflite', 'wb') as f:
f.write(tflite_model)

30 changes: 30 additions & 0 deletions saved_models/inf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import numpy as np
import tensorflow as tf
import cv2

img = cv2.imread("dog.jpeg")
img = cv2.resize(img, (128,128))
img = np.array(img, dtype="float32")
img = np.reshape(img, (1,128,128,3))


# Load the TFLite model and allocate tensors.
interpreter = tf.lite.Interpreter(model_path="model.tflite")
interpreter.allocate_tensors()

# Get input and output tensors.
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()

# Test the model on random input data.
input_shape = input_details[0]['shape']

print("*"*50, input_details)
interpreter.set_tensor(input_details[0]['index'], img)

interpreter.invoke()

# The function `get_tensor()` returns a copy of the tensor data.
# Use `tensor()` in order to get a pointer to the tensor.
output_data = interpreter.get_tensor(output_details[0]['index'])
print(output_data)
Binary file added saved_models/weights.best.ResNet50.hdf5
Binary file not shown.
Binary file added tflite_model.tflite
Binary file not shown.
Binary file added tflite_model_another.tflite
Binary file not shown.
Loading