Ejemplo n.º 1
0
    end_image = (rank + 1) * images_per_process

print("Rank %d, Start %d, End %d" % (rank, start_image, end_image))

# object detection on images for this proces
total_runtime = 0
for _id, _url in enumerate(
        tqdm(image_urls[start_image:end_image], desc="Rank %d" % rank)):
    path = download_and_resize_image(_url, 640, 480)
    img = tf.io.read_file(path)
    img = tf.image.decode_jpeg(img, channels=3)
    converted_img = tf.image.convert_image_dtype(img, tf.float32)[tf.newaxis,
                                                                  ...]

    start_time = time.time()
    result = detector(converted_img)
    end_time = time.time()

    result = {key: value.numpy() for key, value in result.items()}
    objects = list(set(result['detection_class_entities'].tolist()))
    total_runtime = total_runtime + (end_time - start_time)

    # print("Rank %d, image %s, runtime %0.2f"%(rank,path,end_time-start_time))
    mlflow_params["objects"] = objects
    mlflow_metrics["runtime"] = end_time - start_time

    image_with_boxes = draw_boxes(img.numpy(), result["detection_boxes"],
                                  result["detection_class_entities"],
                                  result["detection_scores"])
    filename = save_to_file(image_with_boxes)
Ejemplo n.º 2
0
            picture_labels.append(picture_label)

            # Select Neurons
            print("Selecting Neurons...")
            selected = select_neurons(
                model, target_layers, image_data, base_vars, config,
                activation_cases=base_vars["activation_cases"])
            selected_weight.append(selected)

            if picture_label == 1:
                # Draw Boxes
                print("Drawing Boxes")
                for activation_case, selected_metric in zip(base_vars["activation_cases"], selected):
                    vars_ = unpack(base_vars, activation_case, config)
                    draw_boxes(
                        patches, selected_metric, vars_["img_dir"],
                        picture_name, vars_["width"],
                        vars_["height"], vars_['bounding_box_path'])

                # Calculate the Overlap between the selections by the
                # Activation-Output Correlation metric and the Precision metric
                print("Calculating Overlap")
                overlap = analysis.calc_overlap(selected[4], selected[5])
                overlaps_weight.append(overlap)
                print("Overlap Size: {}".format(overlap))
        overlaps.append(overlaps_weight)

        # Calculate the accuracy for each selection metric
        print("Calculating Accuracies")
        accuracies_weight = []
        for i in range(len(selected_weight[0])):
            X_train, X_test, Y_train, Y_test = get_train_test_sets(
Ejemplo n.º 3
0
                                         [430, 430]])
''' Example code to generate adv_example/color_filtering.png '''
# img = color_filtering(img)
''' Example code to generate adv_example/perspective.png '''
# img = blur(img, (5,5))

#cv2.imwrite('layers_car/large_6.jpg', img)
#objects = localize_objects('layers_car/large_12.jpg')
ret = detect_safe_search('images/0000.png')
print(ret)
'''
for i in range(0, 2000):
    ret = detect_safe_search('images/0000.png')
    print(ret)
'''
'''
labels = []
coords = []
image = Image.open("layers_car/large_12.jpg")
for object in objects:
    label = object.name + ":" + str(object.score)[:4]
    labels.append(label)
    top = object.bounding_poly.normalized_vertices[0].y
    left = object.bounding_poly.normalized_vertices[0].x
    bottom = object.bounding_poly.normalized_vertices[2].y
    right = object.bounding_poly.normalized_vertices[2].x
    coords.append([top, left, bottom, right])

draw_boxes(image, labels, coords)
image.save("images/out.png", "PNG")
'''