{"id":23060450,"url":"https://github.com/paperspace/object-detection-segmentation","last_synced_at":"2025-07-26T11:41:09.439Z","repository":{"id":52686450,"uuid":"282911177","full_name":"Paperspace/object-detection-segmentation","owner":"Paperspace","description":"How to run object detection models on Gradient including re-training and inference","archived":false,"fork":false,"pushed_at":"2023-05-22T22:47:44.000Z","size":29362,"stargazers_count":15,"open_issues_count":1,"forks_count":7,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-03T11:02:02.869Z","etag":null,"topics":["computer-vision","deep-learning","machine-learning","object-detection","tensorflow"],"latest_commit_sha":null,"homepage":"https://gradient.paperspace.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Paperspace.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-27T13:47:00.000Z","updated_at":"2024-04-22T16:14:42.000Z","dependencies_parsed_at":"2024-12-16T03:23:31.343Z","dependency_job_id":null,"html_url":"https://github.com/Paperspace/object-detection-segmentation","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Paperspace/object-detection-segmentation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Paperspace%2Fobject-detection-segmentation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Paperspace%2Fobject-detection-segmentation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Paperspace%2Fobject-detection-segmentation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Paperspace%2Fobject-detection-segmentation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Paperspace","download_url":"https://codeload.github.com/Paperspace/object-detection-segmentation/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Paperspace%2Fobject-detection-segmentation/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267161456,"owners_count":24045474,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-26T02:00:08.937Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computer-vision","deep-learning","machine-learning","object-detection","tensorflow"],"created_at":"2024-12-16T03:12:51.958Z","updated_at":"2025-07-26T11:41:09.431Z","avatar_url":"https://github.com/Paperspace.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![GitHubSplash](https://user-images.githubusercontent.com/585865/65443342-e630d300-ddfb-11e9-9bcd-de1d2033ea60.png)\n\nGradient - PyTorch-based modular object detection based on Detectron Demo\n=================\n\u003cbr\u003e\n\n**Get started:** [Create Account](https://console.paperspace.com/signup?gradient=true) • [Install CLI](https://docs.paperspace.com/gradient/get-started/install-the-cli) • [Tutorials](https://docs.paperspace.com/gradient/tutorials) • [Docs](https://docs.paperspace.com/gradient)\n\n**Resources:** [Website](https://gradient.paperspace.com/) • [Blog](https://blog.paperspace.com/) • [Support](https://support.paperspace.com/hc/en-us) • [Contact Sales](https://info.paperspace.com/contact-sales)\n\n\u003cbr\u003e\n=================\n\n### Blog Post\n\nThis Repository is related to our [Blog post](https://blog.paperspace.com/object-detection-segmentation-with-detectron2-on-paperspace-gradient/) \n\n\n### Training \u0026 Evaluation\n\nPlease check out [docs on using Experiments with Gradient](https://docs.paperspace.com/gradient/experiments/using-experiments)\n\nWe provide an example script in \"training/train_net.py\" that is made to train your model. \nYou can use this as a reference to write your own training script.\n\n### Setup Dataset\n\nThis demo has built-in support for a few datasets.\nPlease check out [docs on using Datasets with Gradient](https://docs.paperspace.com/gradient/experiments/using-experiments/experiment-datasets)\n\nThe datasets are assumed to exist in a directory `/data/DATASET`.\nUnder this directory, the script will look for datasets in the structure described below, if needed.\n```\n/data/coco/\n```\n```\n# Example Code \ndataset_dir = os.path.join(os.getenv(\"DETECTRON2_DATASETS\", \"/data\"), \"coco\")\n```\n#### Expected dataset structure for COCO instance/keypoint detection:\n\n```\ncoco/\n  annotations/\n    instances_{train,val}2017.json\n    person_keypoints_{train,val}2017.json\n  {train,val}2017/\n    # image files that are mentioned in the corresponding json\n```\nYou can download a tiny version of the COCO dataset, with `training/download_coco.sh`.\n\n#### COCO Dataset\nProbably the most widely used dataset today for object localization is COCO: Common Objects in Context. Provided here are all the files from the 2017 version, along with an additional subset dataset created by fast.ai. Details of each COCO dataset is available from the COCO dataset page. The fast.ai subset contains all images that contain one of five selected categories, restricting objects to just those five categories; the categories are: chair couch tv remote book vase.\n\n[fast.ai subset](https://s3.amazonaws.com/fast-ai-coco/coco_sample.tgz)\n\n[Train images](https://s3.amazonaws.com/fast-ai-coco/train2017.zip)\n\n## Run Training on Gradient\n\n### Gradient CLI Installation\n\nHow to install Gradient CLI - [docs](https://docs.paperspace.com/gradient/get-started/install-the-cli)\n\n```\npip install gradient\n```\nThen make sure to [obtain an API Key](https://docs.paperspace.com/gradient/get-started/install-the-cli#obtaining-an-api-key), and then:\n```\ngradient apiKey XXXXXXXXXXXXXXXXXXX\n```\n\n### Train on a single GPU\n\n_Note: training on a single will take a long time, so be prepared to wait!_\n\n```\ngradient experiments run singlenode \\\n  --name detectron2-demo \\\n  --projectId pr3qnl0g8 \\\n  --container devopsbay/detectron2:v1 \\\n  --machineType P4000 \\\n  --command \"sudo python training/train_net.py --config-file training/configs/mask_rcnn_R_50_FPN_1x.yaml --num-gpus 1 SOLVER.IMS_PER_BATCH 2 SOLVER.BASE_LR 0.0025 MODEL.WEIGHTS https://dl.fbaipublicfiles.com/detectron2/COCO-Detection/faster_rcnn_R_50_FPN_1x/137257794/model_final_b275ba.pkl  OUTPUT_DIR /artifacts/models/detectron\" \\\n  --workspace https://github.com/Paperspace/object-detection-segmentation.git \\\n  --datasetName small_coco \\\n  --datasetUri s3://paperspace-tiny-coco/small_coco.zip \\\n  --clusterId \u003cCluster ID\u003e\n```\nThe coco dataset is downloaded to the `./data/coco/traing2017` directory.\nModel results are stored in the `./models` directory.\n\n### Running distributed training on a Gradient private cluster\nIn order to run a an experiment on a [Gradient private cluster](https://docs.paperspace.com/gradient/gradient-private-cloud/about), we need to add few additional parameters:\n```\ngradient experiments run multinode \\\n  --name mask_rcnn_multinode \\\n  --projectId \u003csome project\u003e \\\n  --workerContainer devopsbay/detectron2:v1 \\\n  --workerMachineType P4000 \\\n  --workerCount 7 \\\n  --parameterServerContainer devopsbay/detectron2:v1 \\\n  --parameterServerMachineType P4000 \\\n  --parameterServerCount 1 \\\n  --experimentType GRPC \\\n  --workerCommand \"python training/train_net.py --config-file training/configs/mask_rcnn_R_50_FPN_1x.yaml --num-machines 8 MODEL.WEIGHTS https://dl.fbaipublicfiles.com/detectron2/COCO-Detection/faster_rcnn_R_50_FPN_1x/137257794/model_final_b275ba.pkl  OUTPUT_DIR /artifacts/models/detectron\" \\\n  --parameterServerCommand \"ython training/train_net.py --config-file training/configs/mask_rcnn_R_50_FPN_1x.yaml --num-machines 8 MODEL.WEIGHTS https://dl.fbaipublicfiles.com/detectron2/COCO-Detection/faster_rcnn_R_50_FPN_1x/137257794/model_final_b275ba.pkl  OUTPUT_DIR /artifacts/models/detectron\" \\\n  --workspace https://github.com/Paperspace/object-detection-segmentation.git \\\n  --datasetName small_coco \\\n  --datasetUri s3://paperspace-tiny-coco/small_coco.zip \\\n  --clusterId \u003ccluster id\u003e\n```\n\n## How to deploy model on Gradient\n\nThis example will load previously trained model and launch a web app application with simple interface. \n\n```\ndeployments create /\n--name paperspace-detectron-demo-app /\n--instanceCount 1 /\n--imageUrl devopsbay/detectron2:v1 /\n--machineType V100 /\n--command \"pip3 install -r demo/requirements.txt \u0026\u0026 python demo/app.py\" /\n--workspace https://github.com/Paperspace/object-detection-segmentation.git \n--deploymentType Custom \n--clusterId \u003ccluster id\u003e \n--modelId \u003cmodel id\u003e \n--ports 8080\n```\n![Example](demo/samples/detect.jpeg?raw=true \"Example Object Detection\")\n\n### Adding custom metrics to Inference app\n\nInside demo/ObjectDetector.py you will find a simple example to push custom metrics into gradient.\n[Docs](https://docs.paperspace.com/gradient/metrics/push-metrics)\n\nExample code\n```\nfrom gradient_utils.metrics import MetricsLogger\n\nlogger = MetricsLogger()\nlogger.add_counter(\"inference_count\")\nlogger[\"inference_count\"].inc()\nlogger.push_metrics()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaperspace%2Fobject-detection-segmentation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaperspace%2Fobject-detection-segmentation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaperspace%2Fobject-detection-segmentation/lists"}