D-FINE icon indicating copy to clipboard operation
D-FINE copied to clipboard

got an error with custom dataset float division by zero

Open allexkuk opened this issue 6 months ago • 3 comments

------------------------------------------Start training------------------------------------------- Traceback (most recent call last): File "C:\Users\emm\PycharmProjects\DFINE3119\train.py", line 113, in main(args) File "C:\Users\emm\PycharmProjects\DFINE3119\train.py", line 75, in main solver.fit() File "C:\Users\emm\PycharmProjects\DFINE3119\src\solver\det_solver.py", line 76, in fit train_stats = train_one_epoch( ^^^^^^^^^^^^^^^^ File "C:\Users\emm\PycharmProjects\DFINE3119\src\solver\det_engine.py", line 59, in train_one_epoch for i, (samples, targets) in enumerate( File "C:\Users\emm\PycharmProjects\DFINE3119\src\misc\logger.py", line 253, in log_every header, total_time_str, total_time / len(iterable) ~~~~~~~~~~~^~~~~~~~~~~~~~~ ZeroDivisionError: float division by zero

Process finished with exit code 1

i cheked my .json, images path, structure looks like no problem, tried change images to smaller size, but still got this error. Tried original coco dataset and its work, change to my and it doesnt work. Dont know how to fix

allexkuk avatar Jun 24 '25 06:06 allexkuk

Do your categories start with index 0?

lz1004 avatar Aug 07 '25 04:08 lz1004

If not, you should shfit them to start with zero.

import json

def shift_category_ids(coco_file_path, output_file_path):
    try:
        # Load the COCO JSON file
        with open(coco_file_path, 'r') as file:
            coco_data = json.load(file)

        # Update category IDs in the categories section
        for category in coco_data.get("categories", []):
            category["id"] -= 1

        # Update category IDs in the annotations section
        for annotation in coco_data.get("annotations", []):
            annotation["category_id"] -= 1

        # Save the modified COCO JSON file
        with open(output_file_path, 'w') as file:
            json.dump(coco_data, file, indent=4)
        
        print(f"Modified COCO file saved to: {output_file_path}")

    except Exception as e:
        print(f"An error occurred: {e}")

# Example usage
input_coco_file = "/data/datasets/objects-v1/annotations/instances_train.json"
output_coco_file = "/data/datasets/objects-v1/annotations/instances_train.json"

shift_category_ids(input_coco_file, output_coco_file)

harmluSICKAG avatar Aug 07 '25 04:08 harmluSICKAG

Try to decrease the batch sizes in yaml. It can be caused by too many empty objects in a batch if your dataset is much smaller than default.

sam31046 avatar Oct 06 '25 19:10 sam31046