roboflow / notebooks

Examples and tutorials on using SOTA computer vision models and techniques. Learn everything from old-school ResNet, through YOLO and object-detection transformers like DETR, to the latest models like Grounding DINO and SAM.
https://roboflow.com/models
5.62k stars 885 forks source link

ValueError: xyxy must be a 2D np.ndarray with shape (_, 4), but got shape (0, 0, 4) #342

Open FrankTseng168 opened 3 days ago

FrankTseng168 commented 3 days ago

Search before asking

Notebook name

how_to_finetune_florence_2_on_detection_dataset

Bug

image

Environment

win 11/ python3.11.10/ spyder

Minimal Reproducible Example

No response

Additional

No response

Are you willing to submit a PR?

LinasKo commented 3 days ago

Hi @FrankTseng168 👋

Thank you for the report! I'm failing to reproduce it so far. Do you know when this happens?

Any chance you could print out the shape of prediction.xyxy, before prediction = prediction[np.isin(...)]? Also, are there any matches in classes, for prediction["class_name"]?

FrankTseng168 commented 2 days ago

Hi, LinasKo @.***>

Thank you for your email。Please refer to the following result:

prediction = sv.Detections.from_lmm(sv.LMM.FLORENCE_2, prediction, resolution_wh=image.size)

print(prediction.xyxy)
print(prediction.xyxy.shape)
print(prediction['class_name'])

prediction = prediction[np.isin(prediction['class_name'], CLASSES)]

-> [[3.2000e-01 3.2000e-01 6.3904e+02 6.3904e+02]] (1, 4) ['bed'] [[3.2000e-01 3.2000e-01 6.3904e+02 6.3904e+02]] (1, 4) ['table'] [[3.2000e-01 3.2000e-01 6.3904e+02 6.3904e+02]] (1, 4) ['chair'] [[3.2000e-01 3.2000e-01 6.3904e+02 6.3904e+02]] (1, 4) ['furniture'] [[3.2000e-01 3.2000e-01 6.3904e+02 6.3904e+02]] (1, 4) ['bed'] [[3.2000e-01 3.2000e-01 6.3904e+02 6.3904e+02]] (1, 4) ['tablecloth'] [[3.2000e-01 3.2000e-01 6.3904e+02 6.3904e+02]] (1, 4) ['table'] [[198.72 182.08 227.51999 224.95999] [311.36 189.12 409.28 408.63998]] (2, 4) ['human face' 'person'] [[3.2000e-01 3.2000e-01 6.3904e+02 6.3904e+02]] (1, 4) ['bed'] [[3.2000e-01 3.2000e-01 6.3904e+02 6.3904e+02]] (1, 4) ['human face'] [] (0, 4) None

LinasKo @.***> 於 2024年11月27日 週三 下午10:38寫道:

Hi @FrankTseng168 https://github.com/FrankTseng168 👋

Thank you for the report! I'm failing to reproduce it so far. Do you know when this happens?

Any chance you could print out the shape of prediction.xyxy, before prediction = prediction[np.isin(...)]? Also, are there any matches in classes, for prediction["class_name"]?

— Reply to this email directly, view it on GitHub https://github.com/roboflow/notebooks/issues/342#issuecomment-2504043808, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJ6ULVQWNFHXWDGERVZ3RXL2CXKORAVCNFSM6AAAAABSSNERTOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMBUGA2DGOBQHA . You are receiving this because you were mentioned.Message ID: @.***>

LinasKo commented 2 days ago

Bug confirmed! Very peculiar. I'll let you know when I fix it. Logged here: https://github.com/roboflow/supervision/issues/1694

For now, try this:

if not predictions.is_empty():
    prediction = prediction[np.isin(prediction["class_name"], CLASSES)]

If it still fails, change to if len(predictions.xyxy) > 0: