Want to train a custom Image Dataset by Detectron2 Faster_RCNN model . I am using a wsl2 ubuntu terminal and a VScode in my windows os. In my train.py, I initiate a config_file_path with "configs/COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml" for modelzoo.py. In the Model Zoo Directory -> configs/COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml file is also available but this error happensenter image description here
#train.py
import numpy as np
from detectron2.utils.logger import setup_logger
setup_logger()
from detectron2.data.datasets import register_coco_instances
from detectron2.engine import DefaultTrainer
import os
import pickle
from utils import *
config_file_path = "configs/COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml"
checkpoint_url = "configs/COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml"
output_dir = "./output/object_detection"
num_classes = 1
device = "cuda"
train_dataset_name = "LP_train"
train_image_path = "train"
train_json_annot_path = "train.json"
test_dataset_name = "LP_test"
test_image_path = "test"
test_json_annot_path = "test.json"
###############################################
register_coco_instances(name = train_dataset_name, metadata = {},
json_file=train_json_annot_path, image_root=train_image_path)
register_coco_instances(name=test_dataset_name, metadata={},json_file=test_json_annot_path, image_root=test_image_path)
#plot_samples(dataset_name= train_dataset_name, n = 2)
###############################################
def main():
cfg = get_train_cfg(config_file_path, checkpoint_url, train_dataset_name, test_dataset_name, num_classes,device, output_dir)
#saving cfg
with open(cfg_save_path, 'wb') as f:
pickle.dump(cfg, f, protocol= pickle.HIGHEST_PROTOCOL)
os.makedirs(cfg.OUTPUT_DIR, exist_ok= True)
trainer = DefaultTrainer(cfg)
trainer.resume_or_load(resume= False)
trainer.train()
if __name__ == '__main__':
main( )
#utlis.py
from detectron2.data import DatasetCatalog, MetadataCatalog
from detectron2.utils.visualizer import Visualizer
from detectron2.config import get_cfg
from detectron2 import model_zoo
from detectron2.utils.visualizer import ColorMode
import random
import cv2
import matplotlib.pyplot as plt
def plot_samples(dataset_name, n=1):
dataset_custom = DatasetCatalog.get(dataset_name)
dataset_custom_metadata = MetadataCatalog.get(dataset_name)
for s in random.sample(dataset_custom, n):
img = cv2.imread(s["file_name"])
v = Visualizer(img[:,:,::-1], metadata=dataset_custom_metadata, scale= 0.5)
v = v.draw_dataset_dict(s)
plt.figure(figsize=(15,20))
plt.imshow(v.get_image())
plt.show()
#plt.savefig("matplotlib.png") #save config , don't show
def get_train_cfg(self,config_file_path, checkpoint_url, train_dataset_name, num_classes, device, output_dir):
cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file(config_file_path))
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url(checkpoint_url)
cfg.DATASETS.TRAIN = (train_dataset_name,)
cfg.DATASETS.TEST = (train_dataset_name,)
cfg.DATALOADER.NUM_WORKERS = 5
cfg.SOLVER.IMS_PER_BATCH = 5
cfg.SOLVER.BASE_LR = 0.00025
cfg.SOLVER.MAX_ITER = 1000
cfg.SOLVER.STEPS = []
cfg.MODEL.ROI_HEADS.NUM_CLASSES = num_classes
cfg.MODEL.DEVICE = device
cfg.OUTPUT_DIR = output_dir
return cfg
i tried to change the path - config_file_path = "COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml" checkpoint_url = "COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml"
but than kind of same type of error happened enter image description here, btw I'm a begginer , I'm Expecting by Running this Pre-trained model from Zoo , I'll built a custom dataset of IMAGE for Object recognition!