def resnet_predict_breed(img_path): # extract bottleneck features bottleneck_feature = extract_Resnet50(path_to_tensor(img_path)) # obtain predicted vector predicted_vector = resnet_model.predict(bottleneck_feature) # return dog breed that is predicted by the model return dog_names[np.argmax(predicted_vector)]
def getPredictBreedFromResNet50(imagePath): # extract bottleneck features bottleneck_feature = extract_Resnet50(path_to_tensor(imagePath)) # obtain predicted vector predicted_vector = model_ResNet50.predict(bottleneck_feature) # return dog breed that is predicted by the model return dog_names[np.argmax(predicted_vector)]
def Resnet50_dog_breed_prediction(image_path): # extract bottleneck features bottleneck_feature = extract_Resnet50(path_to_tensor(image_path)) # obtain predicted vector prediction_value = dog_breed_model.predict(bottleneck_feature) # return dog breed name from the list return dog_names[np.argmax(prediction_value)]
def predict_breed(img_path): ''' Predicts the dog breed present in the picture ''' # extract bottleneck features bottleneck_feature = extract_Resnet50(path_to_tensor(img_path)) # obtain predicted vector predicted_vector = dogAnalyzer.predict(bottleneck_feature) # return dog breed that is predicted by the model name = dog_names[np.argmax(predicted_vector)].split('.')[1] return name.replace('_', ' ')
def predict_dog_breed(self, img_path): tensor = self.path_to_tensor(img_path) print(tensor.shape) self.bottleneck_features = extract_Resnet50(tensor) print(self.bottleneck_features.shape) feat_expand = np.expand_dims(self.bottleneck_features, axis=0) print(feat_expand.shape) index = np.argmax(self.Resnet50_model.predict( self.bottleneck_features)) return self.dog_names[index]
def ResNet50_predict_breed(img_path): ''' Function to predict the dog breed by using the ResNet50_model on image IN: img_path - path to image OUT: predicted dog breed with highest probability ''' # extract bottleneck features bottleneck_feature = extract_Resnet50(path_to_tensor(img_path)) # obtain predicted vector predicted_vector = ResNet50_model.predict(bottleneck_feature) # return dog breed that is predicted by the model return dog_names[np.argmax(predicted_vector)]
def getDogPredictFirstThreePlaces(imagePath): # extract bottleneck features bottleneck_feature = extract_Resnet50(path_to_tensor(imagePath)) # obtain predicted vector list predicted_vector = model_ResNet50.predict(bottleneck_feature)[0] breeds = [ dog_names[index] for index in np.argsort(predicted_vector)[::-1][:3] ] scores = np.sort(predicted_vector)[::-1][:3] print('The first three places:') for index, (breed, score) in enumerate(zip(breeds, scores)): print('nr: {}, {}, score: {:.6f}'.format(index + 1, breed, score)) showImage(imagePath)
def predict_dog(img_path): # print(img_path) img_features = extract_Resnet50(path_to_tensor(img_path)) prediction = np.argmax(Resnet50_model.predict(img_features)) # print(dog_names[prediction]) return dog_names[prediction]