[英]PyTorch for Object detection - Image augmentation
I am using PyTorch for object detection and refining an existing model (transfer learning) as described in the following link - https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html
雖然不同的變換用於圖像增強(本教程中的水平翻轉),但本教程沒有提及任何關於變換邊界框/注釋以確保它們與變換后的圖像一致的內容。 我在這里缺少一些基本的東西嗎?
在訓練階段,轉換確實應用於圖像和目標,同時加載數據。 在PennFudanDataset
class 中,我們有這兩行:
if self.transforms is not None:
img, target = self.transforms(img, target)
其中target
是一個字典,其中包含:
target = {}
target["boxes"] = boxes
target["labels"] = labels
target["masks"] = masks
target["image_id"] = image_id
target["area"] = area
target["iscrowd"] = iscrowd
PennFudanDataset
class 中的self.transforms()
設置為包含[transforms.ToTensor(), transforms.Compose()]
的轉換列表, get_transform()
的返回值,同時使用以下方法實例化數據集:
dataset = PennFudanDataset('PennFudanPed', get_transform(train=True))
變換transforms.Compose()
來自T
,這是為 object 檢測任務編寫的自定義變換。 具體來說,在RandomHorizontalFlip()
的__call__
中,我們同時處理圖像和目標(例如,掩碼、關鍵點):
為了完整起見,我從 github repo 中借用代碼:
def __call__(self, image, target):
if random.random() < self.prob:
height, width = image.shape[-2:]
image = image.flip(-1)
bbox = target["boxes"]
bbox[:, [0, 2]] = width - bbox[:, [2, 0]]
target["boxes"] = bbox
if "masks" in target:
target["masks"] = target["masks"].flip(-1)
if "keypoints" in target:
keypoints = target["keypoints"]
keypoints = _flip_coco_person_keypoints(keypoints, width)
target["keypoints"] = keypoints
return image, target
在這里,我們可以了解它們是如何根據圖像對蒙版和關鍵點進行翻轉的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.