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 lines4567789102 unmodified lines13141516171617181920214 unmodified lines26272828293031323233343536363738383940414218 unmodified lines616263636465666768697071727173747375767778777879808182837 unmodified lines9192939293949596975 unmodified lines10310410510510610610710810911016 unmodified lines1271281291291301311321331341351361371381391381401411421435 unmodified lines1491501511501511521531541551561 unmodified line15815916015916016116216316416516416516616716816917016 unmodified lines18718818918818919019119219319419519419619719819934 unmodified lines2342352362352362372382392402411 unmodified line2432442452442462472482498 unmodified lines25825926025926026126226326426519 unmodified lines28528628728628828929029122 unmodified lines3143153163153163173183193203211 unmodified line3233243253243263273283293303313303323333343352 unmodified lines33833934033934134234334434534534634734834935035135135235344 unmodified lines3983994004024014024034043 unmodified lines40840941041241141241341418 unmodified lines4334344354374364374384393 unmodified lines<head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Video Object Detection</title> <title>Perception System</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%); 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: white; color: #1f2933; text-align: center; margin-bottom: 30px; font-size: 2.5rem; text-shadow: 2px 2px 4px rgba(0,0,0,0.2); letter-spacing: 0.5px; }
.main-card { background: white; background: #ffffff; border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); box-shadow: 0 18px 40px rgba(16, 24, 40, 0.12); padding: 40px; }
18 unmodified lines .mode-card { position: relative; padding: 20px; border: 2px solid #e0e0e0; border: 1px solid #d6dbe0; border-radius: 12px; cursor: pointer; transition: all 0.3s ease; text-align: center; background: #f9fafb; }
.mode-card:hover { border-color: #667eea; border-color: #4b5563; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2); box-shadow: 0 6px 16px rgba(16, 24, 40, 0.12); }
.mode-card.selected { border-color: #667eea; background: #f0f4ff; border-color: #1f2933; background: #eef2f6; }
.mode-card.disabled {7 unmodified lines }
.mode-icon { font-size: 2rem; margin-bottom: 10px; display: none; }
.mode-title {5 unmodified lines .mode-badge { display: inline-block; padding: 4px 8px; background: #ffc107; color: white; 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: 2px solid #e0e0e0; 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: #667eea; border-color: #4b5563; }
.file-input-wrapper {5 unmodified lines .file-input-label { display: block; padding: 15px; background: #f8f9fa; border: 2px dashed #ccc; background: #f3f4f6; border: 1px dashed #bfc5cc; border-radius: 8px; text-align: center; cursor: pointer;1 unmodified line }
.file-input-label:hover { border-color: #667eea; background: #f0f4ff; border-color: #4b5563; background: #eceff3; }
.file-input-label.has-file { border-color: #28a745; background: #d4edda; border-color: #1f2933; background: #e8edf2; }
input[type="file"] {16 unmodified lines }
.btn-primary { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; background: #1f2933; color: #f9fafb; }
.btn-primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4); 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: #28a745; color: white; background: #374151; color: #f9fafb; text-decoration: none; border-radius: 6px; display: inline-block;1 unmodified line }
.download-btn:hover { background: #218838; background: #1f2933; }
/* Loading spinner */8 unmodified lines }
.spinner { border: 4px solid #f3f3f3; border-top: 4px solid #667eea; border: 4px solid #e5e7eb; border-top: 4px solid #1f2933; border-radius: 50%; width: 40px; height: 40px;19 unmodified lines top: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); background: rgba(15, 23, 42, 0.5); align-items: center; justify-content: center; }22 unmodified lines
.modal-btn { padding: 10px 24px; background: #667eea; color: white; background: #1f2933; color: #f9fafb; border: none; border-radius: 6px; cursor: pointer;1 unmodified line }
.modal-btn:hover { background: #5568d3; background: #111827; } </style></head><body> <div class="container"> <h1>π₯ Video Object Detection</h1> <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-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) 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 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 Download Processed Video </a> </div> </div>36 unmodified lines37383940404142434445464142434445464748495051525354555657585960616263646536 unmodified lines with 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] 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