This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.image as mpimg | |
def run_app(img_path): | |
## handle cases for a human face, dog, and neither | |
if (face_detector(img_path)): | |
print('hello, human!') | |
else: | |
print('hello, Dog!') | |
img = mpimg.imread(img_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from extract_bottleneck_features import * | |
def Xception_predict_breed(img_path): | |
# extract bottleneck features | |
bottleneck_feature = extract_Xception(path_to_tensor(img_path)) | |
# obtain predicted vector | |
predicted_vector = Xception_model.predict(bottleneck_feature) | |
# return dog breed that is predicted by the model | |
return dog_names[np.argmax(predicted_vector)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tensorflow.keras.callbacks import ModelCheckpoint | |
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy']) | |
epochs = 25 | |
checkpointer = ModelCheckpoint(filepath='saved_models/weights.best.from_scratch.hdf5', | |
verbose=1, save_best_only=True) | |
model.fit(train_tensors, train_targets, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tensorflow.keras.layers import Conv2D, MaxPooling2D, GlobalAveragePooling2D | |
from tensorflow.keras.layers import Dropout, Flatten, Dense | |
from tensorflow.keras.models import Sequential | |
model = Sequential() | |
model.add(Conv2D(16,(2,2),activation='relu',input_shape=(224,224,3))) | |
model.add(MaxPooling2D(2,2)) | |
model.add(Dropout(0.2)) | |
model.add(Conv2D(32,(2,2),activation='relu')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tensorflow.keras.applications.resnet50 import ResNet50 | |
from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictions | |
from tensorflow.keras.preprocessing import image | |
from tqdm import tqdm | |
# define ResNet50 model | |
ResNet50_model = ResNet50(weights='imagenet') | |
def path_to_tensor(img_path): | |
# loads RGB image as PIL.Image.Image type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# returns "True" if face is detected in image stored at img_path | |
def face_detector(img_path): | |
img = cv2.imread(img_path) | |
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |
faces = face_cascade.detectMultiScale(gray) | |
return len(faces) > 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
# extract pre-trained face detector | |
face_cascade = cv2.CascadeClassifier('haarcascades/haarcascade_frontalface_alt.xml') | |
# load color (BGR) image | |
img = cv2.imread(human_files[3]) | |
# convert BGR image to grayscale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# define function to load train, test, and validation datasets | |
def load_dataset(path): | |
data = load_files(path) | |
dog_files = np.array(data['filenames']) | |
dog_targets = np_utils.to_categorical(np.array(data['target']), 133) | |
return dog_files, dog_targets | |
# load train, test, and validation datasets | |
train_files, train_targets = load_dataset('dogImages/train') | |
valid_files, valid_targets = load_dataset('dogImages/valid') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
╔══════╦═════════════════╦═══════════╗ | |
║ ║ Chopstick.Length║ F.P.E ║ | |
╠══════╬═════════════════╬═══════════╣ | |
║ 0 ║ 180 ║ 24.935161 ║ | |
║ 1 ║ 180 ║ 25.483871 ║ | |
║ 2 ║ 180 ║ 26.322903 ║ | |
║ 3 ║ 180 ║ 24.323871 ║ | |
║ 4 ║ 180 ║ 24.968065 ║ | |
║ 5 ║ 180 ║ 23.999677 ║ | |
╚══════╩═════════════════╩═══════════╝ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
╔══════╦══════╦═══════════════════════════════╗ | |
║ ║F.P.E ║Indivisual ║ Chopstick.Length ║ | |
╠══════╬══════╬═══════════╣═══════════════════║ | |
║ 0 ║ 19.55║ 1 ║ 180 ║ | |
║ 1 ║ 27.24║ 2 ║ 180 ║ | |
║ 2 ║ 28.76║ 3 ║ 180 ║ | |
║ 3 ║ 31.19║ 4 ║ 180 ║ | |
║ 4 ║ 21.91║ 5 ║ 180 ║ | |
╚══════╩══════╩═══════════╝═══════════════════╝ |
NewerOlder