Spaces:
Paused
Paused
Zhen Ye commited on
Commit ·
65dd451
1
Parent(s): cac69cc
git commit -m "Handle grounding dino post-process API differences"
Browse filesFiles changed (2)
- demo.html+42-43
- models/detectors/grounding_dino.py+23-7
3 unmodified lines456789102 unmodified lines13141516171819204 unmodified lines252627282930313233343536373839404118 unmodified lines606162636465666768697071727374757677787980817 unmodified lines89909192939495965 unmodified lines10210310410510610710810916 unmodified lines1261271281291301311321331341351361371381391401415 unmodified lines1471481491501511521531541 unmodified line15615715815916016116216316416516616716816 unmodified lines18518618718818919019119219319419519619734 unmodified lines2322332342352362372382391 unmodified line2412422432442452462478 unmodified lines25625725825926026126226319 unmodified lines28328428528628728828922 unmodified lines3123133143153163173183191 unmodified line3213223233243253263273283293303313323332 unmodified lines33633733833934034134234334434534634734834935035135235335444 unmodified lines3994004014024034044053 unmodified lines40941041141241341441518 unmodified lines4344354364374384394403 unmodified lines<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Video Object Detection</title><style>* {margin: 0;2 unmodified lines}body {font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);min-height: 100vh;padding: 20px;}4 unmodified lines}h1 {color: white;text-align: center;margin-bottom: 30px;font-size: 2.5rem;text-shadow: 2px 2px 4px rgba(0,0,0,0.2);}.main-card {background: white;border-radius: 16px;box-shadow: 0 20px 60px rgba(0,0,0,0.3);padding: 40px;}18 unmodified lines.mode-card {position: relative;padding: 20px;border: 2px solid #e0e0e0;border-radius: 12px;cursor: pointer;transition: all 0.3s ease;text-align: center;}.mode-card:hover {border-color: #667eea;transform: translateY(-2px);box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);}.mode-card.selected {border-color: #667eea;background: #f0f4ff;}.mode-card.disabled {7 unmodified lines}.mode-icon {font-size: 2rem;margin-bottom: 10px;}.mode-title {5 unmodified lines.mode-badge {display: inline-block;padding: 4px 8px;background: #ffc107;color: white;font-size: 0.7rem;border-radius: 4px;font-weight: 600;16 unmodified lines.input-group select {width: 100%;padding: 12px;border: 2px solid #e0e0e0;border-radius: 8px;font-size: 1rem;transition: border-color 0.3s;}.input-group input[type="text"]:focus,.input-group select:focus {outline: none;border-color: #667eea;}.file-input-wrapper {5 unmodified lines.file-input-label {display: block;padding: 15px;background: #f8f9fa;border: 2px dashed #ccc;border-radius: 8px;text-align: center;cursor: pointer;1 unmodified line}.file-input-label:hover {border-color: #667eea;background: #f0f4ff;}.file-input-label.has-file {border-color: #28a745;background: #d4edda;}input[type="file"] {16 unmodified lines}.btn-primary {background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);color: white;}.btn-primary:hover:not(:disabled) {transform: translateY(-2px);box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);}.btn:disabled {34 unmodified lines.download-btn {margin-top: 12px;padding: 10px 16px;background: #28a745;color: white;text-decoration: none;border-radius: 6px;display: inline-block;1 unmodified line}.download-btn:hover {background: #218838;}/* Loading spinner */8 unmodified lines}.spinner {border: 4px solid #f3f3f3;border-top: 4px solid #667eea;border-radius: 50%;width: 40px;height: 40px;19 unmodified linestop: 0;width: 100%;height: 100%;background: rgba(0,0,0,0.5);align-items: center;justify-content: center;}22 unmodified lines.modal-btn {padding: 10px 24px;background: #667eea;color: white;border: none;border-radius: 6px;cursor: pointer;1 unmodified line}.modal-btn:hover {background: #5568d3;}</style></head><body><div class="container"><h1>🎥 Video Object Detection</h1><div class="main-card"><!-- Mode Selection -->2 unmodified lines<div class="mode-selector"><label class="mode-card selected"><input type="radio" name="mode" value="object_detection" checked><div class="mode-icon">🎯</div><div class="mode-title">Object Detection</div></label><label class="mode-card"><input type="radio" name="mode" value="segmentation"><div class="mode-icon">🎨</div><div class="mode-title">Segmentation</div></label><label class="mode-card disabled"><input type="radio" name="mode" value="drone_detection"><div class="mode-icon">🚁</div><div class="mode-title">Drone Detection</div><span class="mode-badge">COMING SOON</span></label>44 unmodified lines<label>3. Upload Video</label><div class="file-input-wrapper"><label class="file-input-label" id="fileLabel" for="videoFile">📁 Click to select video file (MP4)</label><input type="file" id="videoFile" accept="video/*"></div>3 unmodified lines<!-- Process Button --><div class="section"><button class="btn btn-primary" id="processBtn" disabled>🚀 Process Video</button></div>18 unmodified lines<div class="video-card-body"><video id="processedVideo" controls autoplay loop></video><a id="downloadBtn" class="download-btn" download="processed.mp4">⬇️ Download Processed Video</a></div></div>3 unmodified lines456789102 unmodified lines1314151617181920214 unmodified lines262728293031323334353637383940414218 unmodified lines61626364656667686970717273747576777879808182837 unmodified lines919293949596975 unmodified lines10310410510610710810911016 unmodified lines1271281291301311321331341351361371381391401411421435 unmodified lines1491501511521531541551561 unmodified line15815916016116216316416516616716816917016 unmodified lines18718818919019119219319419519619719819934 unmodified lines2342352362372382392402411 unmodified line2432442452462472482498 unmodified lines25825926026126226326426519 unmodified lines28528628728828929029122 unmodified lines3143153163173183193203211 unmodified line3233243253263273283293303313323333343352 unmodified lines33833934034134234334434534634734834935035135235344 unmodified lines3983994004014024034043 unmodified lines40840941041141241341418 unmodified lines4334344354364374384393 unmodified lines<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Perception System</title><style>* {margin: 0;2 unmodified lines}body {font-family: "IBM Plex Sans", "Avenir Next", "Helvetica Neue", sans-serif;background: linear-gradient(180deg, #f6f7f9 0%, #eef1f4 100%);color: #1f2933;min-height: 100vh;padding: 20px;}4 unmodified lines}h1 {color: #1f2933;text-align: center;margin-bottom: 30px;font-size: 2.5rem;letter-spacing: 0.5px;}.main-card {background: #ffffff;border-radius: 16px;box-shadow: 0 18px 40px rgba(16, 24, 40, 0.12);padding: 40px;}18 unmodified lines.mode-card {position: relative;padding: 20px;border: 1px solid #d6dbe0;border-radius: 12px;cursor: pointer;transition: all 0.3s ease;text-align: center;background: #f9fafb;}.mode-card:hover {border-color: #4b5563;transform: translateY(-2px);box-shadow: 0 6px 16px rgba(16, 24, 40, 0.12);}.mode-card.selected {border-color: #1f2933;background: #eef2f6;}.mode-card.disabled {7 unmodified lines}.mode-icon {display: none;}.mode-title {5 unmodified lines.mode-badge {display: inline-block;padding: 4px 8px;background: #6b7280;color: #f9fafb;font-size: 0.7rem;border-radius: 4px;font-weight: 600;16 unmodified lines.input-group select {width: 100%;padding: 12px;border: 1px solid #d6dbe0;border-radius: 8px;font-size: 1rem;transition: border-color 0.3s;background: #ffffff;}.input-group input[type="text"]:focus,.input-group select:focus {outline: none;border-color: #4b5563;}.file-input-wrapper {5 unmodified lines.file-input-label {display: block;padding: 15px;background: #f3f4f6;border: 1px dashed #bfc5cc;border-radius: 8px;text-align: center;cursor: pointer;1 unmodified line}.file-input-label:hover {border-color: #4b5563;background: #eceff3;}.file-input-label.has-file {border-color: #1f2933;background: #e8edf2;}input[type="file"] {16 unmodified lines}.btn-primary {background: #1f2933;color: #f9fafb;}.btn-primary:hover:not(:disabled) {transform: translateY(-2px);box-shadow: 0 6px 16px rgba(16, 24, 40, 0.2);}.btn:disabled {34 unmodified lines.download-btn {margin-top: 12px;padding: 10px 16px;background: #374151;color: #f9fafb;text-decoration: none;border-radius: 6px;display: inline-block;1 unmodified line}.download-btn:hover {background: #1f2933;}/* Loading spinner */8 unmodified lines}.spinner {border: 4px solid #e5e7eb;border-top: 4px solid #1f2933;border-radius: 50%;width: 40px;height: 40px;19 unmodified linestop: 0;width: 100%;height: 100%;background: rgba(15, 23, 42, 0.5);align-items: center;justify-content: center;}22 unmodified lines.modal-btn {padding: 10px 24px;background: #1f2933;color: #f9fafb;border: none;border-radius: 6px;cursor: pointer;1 unmodified line}.modal-btn:hover {background: #111827;}</style></head><body><div class="container"><h1>Perception System</h1><div class="main-card"><!-- Mode Selection -->2 unmodified lines<div class="mode-selector"><label class="mode-card selected"><input type="radio" name="mode" value="object_detection" checked><div class="mode-title">Object Detection</div></label><label class="mode-card"><input type="radio" name="mode" value="segmentation"><div class="mode-title">Segmentation</div></label><label class="mode-card disabled"><input type="radio" name="mode" value="drone_detection"><div class="mode-title">Drone Detection</div><span class="mode-badge">COMING SOON</span></label>44 unmodified lines<label>3. Upload Video</label><div class="file-input-wrapper"><label class="file-input-label" id="fileLabel" for="videoFile">Click to select video file (MP4)</label><input type="file" id="videoFile" accept="video/*"></div>3 unmodified lines<!-- Process Button --><div class="section"><button class="btn btn-primary" id="processBtn" disabled>Process Video</button></div>18 unmodified lines<div class="video-card-body"><video id="processedVideo" controls autoplay loop></video><a id="downloadBtn" class="download-btn" download="processed.mp4">Download Processed Video</a></div></div>
36 unmodified lines3738394041424344454647484936 unmodified lineswith torch.no_grad():outputs = self.model(**inputs)target_sizes = torch.tensor([frame.shape[:2]], device=self.device)processed = self.processor.post_process_grounded_object_detection(outputs,inputs["input_ids"],box_threshold=self.box_threshold,text_threshold=self.text_threshold,target_sizes=target_sizes,)[0]boxes = processed["boxes"].cpu().numpy()scores = processed["scores"].cpu().tolist()label_names = list(processed.get("labels") or [])36 unmodified lines373839404142434445464748495051525354555657585960616263646536 unmodified lineswith torch.no_grad():outputs = self.model(**inputs)target_sizes = torch.tensor([frame.shape[:2]], device=self.device)try:processed = self.processor.post_process_grounded_object_detection(outputs,inputs["input_ids"],box_threshold=self.box_threshold,text_threshold=self.text_threshold,target_sizes=target_sizes,)[0]except TypeError:try:processed = self.processor.post_process_grounded_object_detection(outputs,inputs["input_ids"],threshold=self.box_threshold,text_threshold=self.text_threshold,target_sizes=target_sizes,)[0]except TypeError:processed = self.processor.post_process_grounded_object_detection(outputs,inputs["input_ids"],target_sizes=target_sizes,)[0]boxes = processed["boxes"].cpu().numpy()scores = processed["scores"].cpu().tolist()label_names = list(processed.get("labels") or [])
demo.html+42-43
models/detectors/grounding_dino.py+23-7