Skip to content

Commit

Permalink
Merge pull request #139 from roboflow/add-prediction-parameter
Browse files Browse the repository at this point in the history
add `is_prediction` parameter to upload functions
  • Loading branch information
hansent authored Apr 19, 2023
2 parents 1c37df3 + 0496e58 commit 02b717f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions roboflow/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,9 @@ def __image_upload(

return response

def __annotation_upload(self, annotation_path: str, image_id: str):
def __annotation_upload(
self, annotation_path: str, image_id: str, is_prediction: bool = False
):
"""function to upload annotation to the specific project
:param annotation_path: path to annotation you'd like to upload
:param image_id: image id you'd like to upload that has annotations for it.
Expand Down Expand Up @@ -389,6 +391,7 @@ def __annotation_upload(self, annotation_path: str, image_id: str):
"?api_key=",
self.__api_key,
"&name=" + os.path.basename(annotation_path),
"&is_prediction=true" if is_prediction else "",
]
)

Expand Down Expand Up @@ -422,6 +425,7 @@ def upload(
num_retry_uploads: int = 0,
batch_name: str = DEFAULT_BATCH_NAME,
tag_names: list = [],
is_prediction: bool = False,
**kwargs,
):
"""Upload image function based on the RESTful API
Expand All @@ -435,6 +439,7 @@ def upload(
num_retry_uploads (int) - how many times to retry upload on failure
batch_name (str) - name of batch to upload to within project
tag_names (list[str]) - tags to be applied to an image
is_prediction (bool) - whether the annotation data is a prediction rather than ground truth
Returns:
None - returns nothing
Expand Down Expand Up @@ -473,8 +478,10 @@ def upload(
num_retry_uploads=num_retry_uploads,
batch_name=batch_name,
tag_names=tag_names,
is_prediction=is_prediction,
**kwargs,
)

else:
images = os.listdir(image_path)
for image in images:
Expand All @@ -489,6 +496,7 @@ def upload(
num_retry_uploads=num_retry_uploads,
batch_name=batch_name,
tag_names=tag_names,
is_prediction=is_prediction,
**kwargs,
)
print("[ " + path + " ] was uploaded succesfully.")
Expand All @@ -506,6 +514,7 @@ def single_upload(
num_retry_uploads=0,
batch_name=DEFAULT_BATCH_NAME,
tag_names=[],
is_prediction: bool = False,
**kwargs,
):
success = False
Expand Down Expand Up @@ -572,7 +581,9 @@ def single_upload(
# Upload only annotations to image based on image Id (no image)
if annotation_path is not None and image_id is not None and success:
# Get annotation upload response
annotation_response = self.__annotation_upload(annotation_path, image_id)
annotation_response = self.__annotation_upload(
annotation_path, image_id, is_prediction=is_prediction
)
# Check if upload was a success
try:
response_data = annotation_response.json()
Expand Down

0 comments on commit 02b717f

Please sign in to comment.