Problem is obvious actually, my images shape's are not the same with the required shapes. All I'm doing is putting my images to detectron's already prepared function(you can see functions below). How can I fix it?
These functions are preparing data to detectron2 model(for training)
def get_data_dicts(directory, classes):
dataset_dicts = []
for filename in [file for file in os.listdir(directory) if file.endswith('.json')]:
json_file = os.path.join(directory, filename)
with open(json_file) as f:
img_anns = json.load(f)
record = {}
filename = os.path.join(directory, img_anns["imagePath"])
record["file_name"] = filename
record["height"] = 700
record["width"] = 700
annos = img_anns["shapes"]
objs = []
for anno in annos:
px = [a[0] for a in anno['points']] # x coord
py = [a[1] for a in anno['points']] # y-coord
poly = [(x, y) for x, y in zip(px, py)] # poly for segmentation
poly = [p for x in poly for p in x]
obj = {
"bbox": [np.min(px), np.min(py), np.max(px), np.max(py)],
"bbox_mode": BoxMode.XYXY_ABS,
"category_id": classes.index(anno['label']),
"segmentation": [poly],
"iscrowd": 0
}
objs.append(obj)
record["annotations"] = objs
dataset_dicts.append(record)
return dataset_dicts
classes = ['bos_el', 'dolu_el']
data_path = '/home/berkay/Masaüstü/detectron_data/'
for d in ["test", "train"]:
DatasetCatalog.register(
"my_" + d,
lambda d=d: get_data_dicts(data_path+d, classes)
)
MetadataCatalog.get("my_" + d).set(thing_classes=classes)