Skip to content

Commit

Permalink
add batch_name parameter to command line
Browse files Browse the repository at this point in the history
  • Loading branch information
tonylampada committed Mar 6, 2024
1 parent 32f252b commit f3ca07c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions CLI-COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ options:
-w WORKSPACE specify a workspace url or id (will use default workspace if not specified)
-p PROJECT project will be created if it does not exist
-c CONCURRENCY how many image uploads to perform concurrently (default: 10)
-n BATCH_NAME name of batch to upload to within project
```

## Example: download dataset
Expand Down
12 changes: 8 additions & 4 deletions roboflow/adapters/rfapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import requests
from requests_toolbelt.multipart.encoder import MultipartEncoder

from roboflow.config import API_URL, DEFAULT_BATCH_NAME
from roboflow.config import API_URL, DEFAULT_BATCH_NAME, DEFAULT_JOB_NAME
from roboflow.util import image_utils


Expand Down Expand Up @@ -58,7 +58,6 @@ def upload_image(

# If image is not a hosted image
if not hosted_image:
batch_name = batch_name or DEFAULT_BATCH_NAME
image_name = os.path.basename(image_path)
imgjpeg = image_utils.file2jpeg(image_path)

Expand Down Expand Up @@ -103,6 +102,7 @@ def save_annotation(
annotation_name: str,
annotation_string: str,
image_id: str,
job_name: str = DEFAULT_JOB_NAME,
is_prediction: bool = False,
annotation_labelmap=None,
overwrite: bool = False,
Expand All @@ -115,7 +115,9 @@ def save_annotation(
image_id (str): image id you'd like to upload that has annotations for it.
"""

upload_url = _save_annotation_url(api_key, project_url, annotation_name, image_id, is_prediction, overwrite)
upload_url = _save_annotation_url(
api_key, project_url, annotation_name, image_id, job_name, is_prediction, overwrite
)

response = requests.post(
upload_url,
Expand Down Expand Up @@ -143,8 +145,10 @@ def save_annotation(
return responsejson


def _save_annotation_url(api_key, project_url, name, image_id, is_prediction, overwrite=False):
def _save_annotation_url(api_key, project_url, name, image_id, job_name, is_prediction, overwrite=False):
url = f"{API_URL}/dataset/{project_url}/annotate/{image_id}?api_key={api_key}" f"&name={name}"
if job_name:
url += f"&jobName={job_name}"
if is_prediction:
url += "&prediction=true"
if overwrite:
Expand Down
1 change: 1 addition & 0 deletions roboflow/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def get_conditional_configuration_variable(key, default):
TYPE_SEMANTIC_SEGMENTATION = "semantic-segmentation"

DEFAULT_BATCH_NAME = "Pip Package Upload"
DEFAULT_JOB_NAME = "Annotated via API"

RF_WORKSPACES = get_conditional_configuration_variable("workspaces", default={})

Expand Down
7 changes: 4 additions & 3 deletions roboflow/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from PIL import Image, UnidentifiedImageError

from roboflow.adapters import rfapi
from roboflow.config import API_URL, DEFAULT_BATCH_NAME, DEMO_KEYS
from roboflow.config import API_URL, DEMO_KEYS
from roboflow.core.version import Version
from roboflow.util.general import retry
from roboflow.util.image_utils import load_labelmap
Expand Down Expand Up @@ -362,7 +362,7 @@ def upload(
image_id: str = None,
split: str = "train",
num_retry_uploads: int = 0,
batch_name: str = DEFAULT_BATCH_NAME,
batch_name: str = None,
tag_names: list = [],
is_prediction: bool = False,
**kwargs,
Expand Down Expand Up @@ -455,7 +455,7 @@ def single_upload(
image_id=None,
split="train",
num_retry_uploads=0,
batch_name=DEFAULT_BATCH_NAME,
batch_name=None,
tag_names=[],
is_prediction: bool = False,
annotation_overwrite=False,
Expand Down Expand Up @@ -507,6 +507,7 @@ def single_upload(
annotation_name,
annotation_str,
image_id,
job_name=batch_name,
is_prediction=is_prediction,
annotation_labelmap=annotation_labelmap,
overwrite=annotation_overwrite,
Expand Down
2 changes: 2 additions & 0 deletions roboflow/core/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ def upload_dataset(
num_workers: int = 10,
project_license: str = "MIT",
project_type: str = "object-detection",
batch_name=None,
):
"""
Upload a dataset to Roboflow.
Expand Down Expand Up @@ -344,6 +345,7 @@ def _upload_image(imagedesc):
split=split,
sequence_number=imagedesc.get("index"),
sequence_size=len(images),
batch_name=batch_name,
)
_log_img_upload(image_path, uploadres)
except Exception as e:
Expand Down
12 changes: 7 additions & 5 deletions roboflow/roboflowpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import roboflow
from roboflow import config as roboflow_config
from roboflow.adapters import rfapi
from roboflow.config import APP_URL, DEFAULT_BATCH_NAME, get_conditional_configuration_variable, load_roboflow_api_key
from roboflow.config import APP_URL, get_conditional_configuration_variable, load_roboflow_api_key
from roboflow.models.classification import ClassificationModel
from roboflow.models.instance_segmentation import InstanceSegmentationModel
from roboflow.models.object_detection import ObjectDetectionModel
Expand Down Expand Up @@ -48,9 +48,7 @@ def import_dataset(args):
rf = roboflow.Roboflow()
workspace = rf.workspace(args.workspace)
workspace.upload_dataset(
dataset_path=args.folder,
project_name=args.project,
num_workers=args.concurrency,
dataset_path=args.folder, project_name=args.project, num_workers=args.concurrency, batch_name=args.batch_name
)


Expand Down Expand Up @@ -212,7 +210,6 @@ def _add_upload_parser(subparsers):
"-b",
dest="batch",
help="Batch name to upload to (optional)",
default=DEFAULT_BATCH_NAME,
)
upload_parser.add_argument(
"-t",
Expand Down Expand Up @@ -251,6 +248,11 @@ def _add_import_parser(subparsers):
help="how many image uploads to perform concurrently (default: 10)",
default=10,
)
import_parser.add_argument(
"-n",
dest="batch_name",
help="name of batch to upload to within project",
)
import_parser.set_defaults(func=import_dataset)


Expand Down
2 changes: 1 addition & 1 deletion tests/manual/debugme.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@
# f"import {thisdir}/data/cultura-pepino-coco -w wolfodorpythontests -p yellow-auto -c 100".split() # noqa: E501 // docs
# f"import {thisdir}/data/cultura-pepino-yolov8 -w wolfodorpythontests -p yellow-auto -c 100".split() # noqa: E501 // docs
# f"import {thisdir}/data/cultura-pepino-yolov8_voc -w wolfodorpythontests -p yellow-auto -c 100".split() # noqa: E501 // docs
f"import {thisdir}/data/cultura-pepino-yolov5pytorch -w wolfodorpythontests -p yellow-auto -c 100".split() # noqa: E501 // docs
f"import {thisdir}/data/cultura-pepino-yolov5pytorch -w wolfodorpythontests -p yellow-auto -c 100 -n papaiasso".split() # noqa: E501 // docs
)
args.func(args)

0 comments on commit f3ca07c

Please sign in to comment.