write letterboxresize such that it resizes the input image and bounding box annotations…
- User
write letterbox_resize such that it resizes the input image and bounding box annotations to the input_shape_chw while maintaining the aspect ratio def annotation_to_boxes(annotation_filepath): with open(annotation_filepath) as file: lines = [line for line in file.read().split('\n') if line != ''] boxes_cxcywh = torch.zeros(len(lines), 4) labels = torch.zeros(len(lines), 1) for i, line in enumerate(lines): obj = torch.tensor([float(item) for item in line.split(' ')]) boxes_cxcywh[i] = obj[1:] labels[i] = obj[0] return boxes_cxcywh, labels
def letterbox_resize(image, boxes_cxcywh, input_shape_chw): pass
image_path = 'datasets/voc2007/yolo/test_toy_3/data/000082.jpg' annotations_path = 'datasets/voc2007/yolo/test_toy_3/data/000082.txt' input_shape_chw = [3, 384, 384]
boxes_cxcywh, labels = annotation_to_boxes(annotations_path) image = Image.open(image_path) image, boxes_cxcywh = letterbox_resize(image, boxes_cxcywh, input_shape_chw)
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.