full_body_anonymization icon indicating copy to clipboard operation
full_body_anonymization copied to clipboard

Generating embeddings for new training samples

Open KyriaAnnwyn opened this issue 2 years ago • 3 comments

How to generate embeddings for my training set?

KyriaAnnwyn avatar May 04 '22 14:05 KyriaAnnwyn

Code for generating embeddings for new training datasets is currently not supported, but it should not be that much required.

The following code detects an image, crops the different detections and post processes the embedding/image to generate a single annotated image for each detection.

import torchvision
from fba.anonymizer.cse import CSEDetector
from fba.anonymizer.post_process import process_cse_detections

input_path = "coco_val2017_000000001000.jpg"
im = torchvision.io.read_image(input_path, mode=torchvision.io.ImageReadMode.RGB)
detector = CSEDetector()
detections = detector(im)
embed_map = detections["embed_map"]
if detections is None:
    exit()
post_process_cfg = dict(
    target_imsize=(288, 160),
    exp_bbox_cfg=dict(percentage_background=0.3, axis_minimum_expansion=.1),
    exp_bbox_filter=dict(minimum_area=32*32, min_bbox_ratio_inside=0, aspect_ratio_range=[0, 99999]),
)
detections = process_cse_detections(
    im, **detections, **post_process_cfg
)
for i, sample in enumerate(detections):
    print("Detection:", i)
    for key, value in sample.items():
        if key == "exp_bbox":
            print(key, value)
        elif key == "N":
            continue
        else:
            print(key, value.shape, value.dtype)

Hope this helps out!

hukkelas avatar May 05 '22 06:05 hukkelas

@hukkelas Great! Thank you for your quick answer!

KyriaAnnwyn avatar May 05 '22 07:05 KyriaAnnwyn

My pleasure :)

hukkelas avatar May 05 '22 09:05 hukkelas