Beispiel #1
0
    def _obtain_y_pred(self,
                       prob_threshold=0.75):

        y_pred = []
        y_scores = []

        predicted_class_list = []
        actual_class_list = []
        coverage_count = 0

        for hra_class in self.sorted_categories_names:

            # variable that contains the main dir alongside the selected category
            tmp = os.path.join(self.main_test_dir, hra_class)
            img_names = sorted(os.listdir(tmp))

            for raw_img in img_names:
                # variable that contains the final image to be loaded
                print(' Processing  [' + raw_img + ']')
                final_img = os.path.join(tmp, raw_img)

                preds = displaceNet_inference(img_path=final_img,
                                              emotic_model_a_backend_name=self.emotic_model_a_backend_name,
                                              emotic_model_b_backend_name=self.emotic_model_b_backend_name,
                                              emotic_model_c_backend_name=self.emotic_model_c_backend_name,
                                              hra_model_backend_name=self.hra_model_backend_name,
                                              nb_of_fine_tuned_conv_layers=self.nb_of_conv_layers_to_fine_tune,
                                              violation_class=self.violation_class)


                preds = preds[0]

                y_pred.append(int(preds[0][0]))
                y_scores.append(preds[0][2])

                top_1_predicted_probability = preds[0][2]

                # top_1_predicted = np.argmax(preds)
                top_1_predicted_label = preds[0][1]

                if top_1_predicted_probability >= prob_threshold:
                    coverage_count += 1

                # print ('`' + hra_class + '/' + raw_img + '`  ===>  `' +
                #        top_1_predicted_label + '`' + ' with ' + str(top_1_predicted_probability) + ' P')

                print('     GT `' + hra_class + '`' + '` <--> ` Pred. `' +
                      top_1_predicted_label + '`' + ' with ' + str(top_1_predicted_probability))

                print ('\n')

                predicted_class_list.append(top_1_predicted_label)
                actual_class_list.append(hra_class)

        total_coverage_per = (coverage_count * 100) / self.total_nb_of_test_images

        return y_pred, self.y_true, y_scores, total_coverage_per
Beispiel #2
0
                                                                                            model_backend_name=hra_model_backend_name,
                                                                                            nb_of_conv_layers_to_fine_tune=nb_of_conv_layers_to_fine_tune)


img = image.load_img(img_path, target_size=(224, 224))
print ('Vanilla CNN prediction: ', raw_preds[0])


emotic_model_a_backend_name = 'VGG16'
emotic_model_b_backend_name = None
emotic_model_c_backend_name = None

final_preds = displaceNet_inference(img_path,
                                    emotic_model_a_backend_name,
                                    emotic_model_b_backend_name,
                                    emotic_model_c_backend_name,
                                    hra_model_backend_name,
                                    nb_of_conv_layers_to_fine_tune,
                                    violation_class)



print('DisplaceNet prediction: ', final_preds)

numpy_img_path = imread(img_path)
plt.figure(figsize=(10, 12))
plt.imshow(numpy_img_path)

current_axis = plt.gca()

# configure colours for bounding box and text
'''

'''
from __future__ import print_function
import argparse
from inference.displacenet_single_image_inference_unified import displaceNet_inference


def get_args():
    parser = argparse.ArgumentParser()
    parser.add_argument("--img_path", type = str,help = 'path of the input image')
    parser.add_argument("--hra_model_backend_name", type = str,help = 'One of `VGG16`, `VGG19`, `ResNet50` or `VGG16_Places365`')
    parser.add_argument("--emotic_model_backend_name", type=str, help='One of `VGG16`, `VGG19` or `ResNet50`')
    parser.add_argument("--nb_of_conv_layers_to_fine_tune", type=int, help='indicates the number of convolutional layers that were fine-tuned during training')

    args = parser.parse_args()
    return args

args = get_args()


DisplaceNet_preds = displaceNet_inference(img_path=args.img_path,
                                          emotic_model_a_backend_name=args.emotic_model_backend_name,
                                          emotic_model_b_backend_name=None,
                                          emotic_model_c_backend_name=None,
                                          hra_model_backend_name=args.hra_model_backend_name,
                                          nb_of_fine_tuned_conv_layers=args.nb_of_conv_layers_to_fine_tune,
                                          violation_class='dp')

print (DisplaceNet_preds)
print (DisplaceNet_preds[0])