Skip to content

Commit 324451c

Browse files
authored
Merge pull request #322 from roboflow/feat/yolo11-seg-deployment
Add deployment instructions for yolo11-seg
2 parents db5d8ff + d7788a0 commit 324451c

File tree

2 files changed

+96
-12
lines changed

2 files changed

+96
-12
lines changed

notebooks/train-yolo11-instance-segmentation-on-custom-dataset.ipynb

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,84 @@
917917
}
918918
]
919919
},
920+
{
921+
"cell_type": "markdown",
922+
"source": [
923+
"## Deploy model on Roboflow\n",
924+
"\n",
925+
"Once you have finished training your YOLOv11 model, you’ll have a set of trained weights ready for use. These weights will be in the `/runs/segment/train/weights/best.pt` folder of your project. You can upload your model weights to Roboflow Deploy to use your trained weights on our infinitely scalable infrastructure.\n",
926+
"\n",
927+
"The `.deploy()` function in the [Roboflow pip package](https://docs.roboflow.com/python) now supports uploading YOLOv11 weights."
928+
],
929+
"metadata": {
930+
"id": "4Z2R1eJiz4ux"
931+
}
932+
},
933+
{
934+
"cell_type": "code",
935+
"source": [
936+
"project.version(dataset.version).deploy(model_type=\"yolov11-seg\", model_path=f\"{HOME}/runs/segment/train/\")"
937+
],
938+
"metadata": {
939+
"id": "IjZQqXwU0UEo"
940+
},
941+
"execution_count": null,
942+
"outputs": []
943+
},
944+
{
945+
"cell_type": "code",
946+
"source": [
947+
"!pip install inference"
948+
],
949+
"metadata": {
950+
"id": "pz765jno0Xl3"
951+
},
952+
"execution_count": null,
953+
"outputs": []
954+
},
955+
{
956+
"cell_type": "code",
957+
"source": [
958+
"import os, random, cv2\n",
959+
"import supervision as sv\n",
960+
"import IPython\n",
961+
"import inference\n",
962+
"\n",
963+
"model_id = project.id.split(\"/\")[1] + \"/\" + dataset.version\n",
964+
"model = inference.get_model(model_id, userdata.get('ROBOFLOW_API_KEY'))\n",
965+
"\n",
966+
"# Location of test set images\n",
967+
"test_set_loc = dataset.location + \"/test/images/\"\n",
968+
"test_images = os.listdir(test_set_loc)\n",
969+
"\n",
970+
"# Run inference on 4 random test images, or fewer if fewer images are available\n",
971+
"for img_name in random.sample(test_images, min(4, len(test_images))):\n",
972+
" print(\"Running inference on \" + img_name)\n",
973+
"\n",
974+
" # Load image\n",
975+
" image = cv2.imread(os.path.join(test_set_loc, img_name))\n",
976+
"\n",
977+
" # Perform inference\n",
978+
" results = model.infer(image)[0]\n",
979+
" detections = sv.Detections.from_inference(results)\n",
980+
"\n",
981+
" # Annotate boxes and labels\n",
982+
" mask_annotator = sv.MaskAnnotator()\n",
983+
" label_annotator = sv.LabelAnnotator()\n",
984+
" annotated_image = mask_annotator.annotate(scene=image, detections=detections)\n",
985+
" annotated_image = label_annotator.annotate(scene=annotated_image, detections=detections)\n",
986+
"\n",
987+
" # Display annotated image\n",
988+
" _, ret = cv2.imencode('.jpg', annotated_image)\n",
989+
" i = IPython.display.Image(data=ret)\n",
990+
" IPython.display.display(i)\n"
991+
],
992+
"metadata": {
993+
"id": "seFGjEE20X05"
994+
},
995+
"execution_count": null,
996+
"outputs": []
997+
},
920998
{
921999
"cell_type": "markdown",
9221000
"source": [

notebooks/train-yolo11-object-detection-on-custom-dataset.ipynb

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -888,21 +888,23 @@
888888
},
889889
{
890890
"cell_type": "markdown",
891-
"metadata": {},
891+
"metadata": {
892+
"id": "fUFNm4O0znB2"
893+
},
892894
"source": [
893895
"## Deploy model on Roboflow\n",
894896
"\n",
895897
"Once you have finished training your YOLOv11 model, you’ll have a set of trained weights ready for use. These weights will be in the `/runs/detect/train/weights/best.pt` folder of your project. You can upload your model weights to Roboflow Deploy to use your trained weights on our infinitely scalable infrastructure.\n",
896898
"\n",
897-
"The `.deploy()` function in the [Roboflow pip package](https://docs.roboflow.com/python) now supports uploading YOLOv11 weights.\n",
898-
"\n",
899-
"To upload model weights, add the following code to the “Inference with Custom Model” section in the aforementioned notebook:"
899+
"The `.deploy()` function in the [Roboflow pip package](https://docs.roboflow.com/python) now supports uploading YOLOv11 weights."
900900
]
901901
},
902902
{
903903
"cell_type": "code",
904904
"execution_count": null,
905-
"metadata": {},
905+
"metadata": {
906+
"id": "3Y6_K1MRznB2"
907+
},
906908
"outputs": [],
907909
"source": [
908910
"project.version(dataset.version).deploy(model_type=\"yolov11\", model_path=f\"{HOME}/runs/detect/train/\")"
@@ -911,7 +913,9 @@
911913
{
912914
"cell_type": "code",
913915
"execution_count": null,
914-
"metadata": {},
916+
"metadata": {
917+
"id": "V5K2IU_SznB2"
918+
},
915919
"outputs": [],
916920
"source": [
917921
"!pip install inference"
@@ -920,7 +924,9 @@
920924
{
921925
"cell_type": "code",
922926
"execution_count": null,
923-
"metadata": {},
927+
"metadata": {
928+
"id": "BwYVU9S5znB2"
929+
},
924930
"outputs": [],
925931
"source": [
926932
"import os, random, cv2\n",
@@ -938,20 +944,20 @@
938944
"# Run inference on 4 random test images, or fewer if fewer images are available\n",
939945
"for img_name in random.sample(test_images, min(4, len(test_images))):\n",
940946
" print(\"Running inference on \" + img_name)\n",
941-
" \n",
947+
"\n",
942948
" # Load image\n",
943949
" image = cv2.imread(os.path.join(test_set_loc, img_name))\n",
944-
" \n",
950+
"\n",
945951
" # Perform inference\n",
946952
" results = model.infer(image, confidence=0.4, overlap=30)[0]\n",
947953
" detections = sv.Detections.from_inference(results)\n",
948-
" \n",
954+
"\n",
949955
" # Annotate boxes and labels\n",
950956
" box_annotator = sv.BoxAnnotator()\n",
951957
" label_annotator = sv.LabelAnnotator()\n",
952958
" annotated_image = box_annotator.annotate(scene=image, detections=detections)\n",
953959
" annotated_image = label_annotator.annotate(scene=annotated_image, detections=detections)\n",
954-
" \n",
960+
"\n",
955961
" # Display annotated image\n",
956962
" _, ret = cv2.imencode('.jpg', annotated_image)\n",
957963
" i = IPython.display.Image(data=ret)\n",
@@ -1011,4 +1017,4 @@
10111017
},
10121018
"nbformat": 4,
10131019
"nbformat_minor": 0
1014-
}
1020+
}

0 commit comments

Comments
 (0)