Python 如何扩展此对象检测pytorch程序来检测和分类多个类?
我遵循了构建对象检测器的教程,现在我正在尝试扩展它以识别更多的类 这种目标检测算法只适用于一个类别(浣熊),但是可以使用更大的数据集训练神经网络来识别更多类别 它使用一个预训练的更快的网络 有人能帮我修改代码,这样它就可以区分多个类了吗 提前谢谢Python 如何扩展此对象检测pytorch程序来检测和分类多个类?,python,neural-network,pytorch,object-detection,torch,Python,Neural Network,Pytorch,Object Detection,Torch,我遵循了构建对象检测器的教程,现在我正在尝试扩展它以识别更多的类 这种目标检测算法只适用于一个类别(浣熊),但是可以使用更大的数据集训练神经网络来识别更多类别 它使用一个预训练的更快的网络 有人能帮我修改代码,这样它就可以区分多个类了吗 提前谢谢 class RaccoonDataset(torch.utils.data.Dataset): def __init__(self, root, data_file, transforms=None): self.root =
class RaccoonDataset(torch.utils.data.Dataset):
def __init__(self, root, data_file, transforms=None):
self.root = root
self.transforms = transforms
self.imgs = sorted(os.listdir(os.path.join(root, "images")))
self.path_to_data_file = data_file
def __getitem__(self, idx):
# load images and bounding boxes
img_path = os.path.join(self.root, "images", self.imgs[idx])
img = Image.open(img_path).convert("RGB")
box_list = parse_one_annot(self.path_to_data_file,
self.imgs[idx])
boxes = torch.as_tensor(box_list, dtype=torch.float32)
num_objs = len(box_list)
# there is only one class
labels = torch.ones((num_objs,), dtype=torch.int64)
image_id = torch.tensor([idx])
area = (boxes[:, 3] - boxes[:, 1]) * (boxes[:, 2] - boxes[:, 0])
# suppose all instances are not crowd
iscrowd = torch.zeros((num_objs,), dtype=torch.int64)
target = {}
target["boxes"] = boxes
target["labels"] = labels
target["image_id"] = image_id
target["area"] = area
target["iscrowd"] = iscrowd
if self.transforms is not None:
img, target = self.transforms(img, target)
return img, target
def __len__(self):
return len(self.imgs)