Instructions to use harness-race/opencode-r3 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use harness-race/opencode-r3 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("object-detection", model="harness-race/opencode-r3")# pip install -U transformers accelerate # Load model directly from transformers import AutoImageProcessor, AutoModelForObjectDetection processor = AutoImageProcessor.from_pretrained("harness-race/opencode-r3") model = AutoModelForObjectDetection.from_pretrained("harness-race/opencode-r3", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload train_detr.py with huggingface_hub
Browse files- train_detr.py +5 -5
train_detr.py
CHANGED
|
@@ -218,7 +218,7 @@ t_start = time.time()
|
|
| 218 |
log("starting training; epochs", ARGS.epochs, "batch", ARGS.batch_size)
|
| 219 |
for epoch in range(1, ARGS.epochs+1):
|
| 220 |
model.train()
|
| 221 |
-
ep_loss = 0.0;
|
| 222 |
for images, anns, sizes, idx in tqdm(train_dl, desc="epoch %d"%epoch):
|
| 223 |
anns_pp = [{"image_id": int(idx[k]), "annotations": anns[k]} for k in range(len(images))]
|
| 224 |
enc = processor(images=images, annotations=anns_pp, return_tensors="pt")
|
|
@@ -230,14 +230,14 @@ for epoch in range(1, ARGS.epochs+1):
|
|
| 230 |
loss.backward()
|
| 231 |
optim.step()
|
| 232 |
ep_loss += loss.item()
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
ep_giou += out.loss_giou.item()
|
| 236 |
nb += 1
|
| 237 |
global_step += 1
|
| 238 |
if ARGS.max_steps and global_step >= ARGS.max_steps:
|
| 239 |
break
|
| 240 |
-
log("epoch %d loss %.4f
|
|
|
|
| 241 |
m = evaluate()
|
| 242 |
log("VAL", json.dumps(m))
|
| 243 |
if m and m["AP"] > best["AP"]:
|
|
|
|
| 218 |
log("starting training; epochs", ARGS.epochs, "batch", ARGS.batch_size)
|
| 219 |
for epoch in range(1, ARGS.epochs+1):
|
| 220 |
model.train()
|
| 221 |
+
ep_loss = 0.0; ep_losssum = {}; nb = 0
|
| 222 |
for images, anns, sizes, idx in tqdm(train_dl, desc="epoch %d"%epoch):
|
| 223 |
anns_pp = [{"image_id": int(idx[k]), "annotations": anns[k]} for k in range(len(images))]
|
| 224 |
enc = processor(images=images, annotations=anns_pp, return_tensors="pt")
|
|
|
|
| 230 |
loss.backward()
|
| 231 |
optim.step()
|
| 232 |
ep_loss += loss.item()
|
| 233 |
+
for kk, vv in out.loss_dict.items():
|
| 234 |
+
ep_losssum[kk] = ep_losssum.get(kk, 0.0) + vv.detach().item()
|
|
|
|
| 235 |
nb += 1
|
| 236 |
global_step += 1
|
| 237 |
if ARGS.max_steps and global_step >= ARGS.max_steps:
|
| 238 |
break
|
| 239 |
+
log("epoch %d loss %.4f %s" % (epoch, ep_loss/nb,
|
| 240 |
+
" ".join("%s %.4f"%(k, v/nb) for k,v in ep_losssum.items())))
|
| 241 |
m = evaluate()
|
| 242 |
log("VAL", json.dumps(m))
|
| 243 |
if m and m["AP"] > best["AP"]:
|