Created
June 12, 2022 21:10
-
-
Save adaltof/14da966a84d0058870dcd675d410770a to your computer and use it in GitHub Desktop.
Identifying if image is human or dog and providing prediction on dog breed
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
### Function that takes a path to an image as input | |
### and returns the dog breed that is predicted by the model. | |
def predict_breed(img_path): | |
# extract bottleneck features | |
bottleneck_feature = extract_Resnet50(path_to_tensor(img_path)) | |
# obtain predicted vector | |
predicted_vector = new_model.predict(bottleneck_feature) | |
# return dog breed that is predicted by the model | |
return dog_names[np.argmax(predicted_vector)] | |
### Visualization function that shows the image of the dog and prints predicted dog breed | |
def check_dog_image(dog): | |
image_show = cv2.imread(dog) | |
image_show = cv2.cvtColor(image_show, cv2.COLOR_BGR2RGB) | |
plt.imshow(image_show) | |
### Human Dog Detector Function (Goal function) | |
def human_dog_detector(img_path): | |
''' | |
Function to identify if a human face is identified or not, and provide a most likely | |
dog breed that resembles the image, according to our model predictor (default = check_dog_image_VGG16). | |
input img_path: path to image file | |
input predictor: function that returns dog breed prediction according to a ML model | |
output: None | |
''' | |
if face_detector(img_path): | |
print(f'This is probably a human!') | |
else: | |
print(f'We detected a dog!') | |
check_dog_image(img_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment