roboflow / roboflow-python

The official Roboflow Python package. Manage your datasets, models, and deployments. Roboflow has everything you need to build a computer vision application.
https://docs.roboflow.com/python
Apache License 2.0
272 stars 71 forks source link

REST API incomplete image urls paths + search functions cant get uploaded image ID for hardcode URL #256

Open Kyewn opened 3 months ago

Kyewn commented 3 months ago

Image URL paths returned from image detail REST API is: https://source.roboflow.com/[owner_id]/undefined/original.jpg

Image URL paths only working if follow this format: https://source.roboflow.com/[owner_id]/[image_id]/original.jpg

Do excuse me If this is out of scope as I don't see other repos to report this issue.

yeldarby commented 3 months ago

Hi thanks for reporting; could you provide the code snippet used where you got these URLs?

Kyewn commented 3 months ago

Was just testing out the API in the browser and no code written. I browsed using this form of URL https://api.roboflow.com/my-workspace/my-project-name/images/image-id?api_key=ROBOFLOW_API_KEY

Kyewn commented 3 months ago

I can hardcode the URL format because I'm also planning to query for them in my Python server. I have a route for uploading new data to my Roboflow workspace:

@register.route('/register', methods=['POST'])
def register_user():
    data = request.get_json()

    id = data["id"]
    name = data["name"]
    images = list(data["images"])

    # Save images locally first to get path
    # Create folders on init
    # TODO Relocate dir create commands to respective functions
    pathlib.Path('./images').mkdir(parents=True, exist_ok=True)
    pathlib.Path('./images/new_faces').mkdir(parents=True, exist_ok=True)
    pathlib.Path('./images/new_items').mkdir(parents=True, exist_ok=True)

    # Temporarily write image files locally for upload later 
    imageIds = []
    for (i, image) in enumerate(images):
        filePath = f"./images/new_faces/{id}_{name}_{i}.jpg"
        bImage = base64.b64decode(image)
        with open(filePath, "wb") as image:
            image.write(bImage)
            image.close()

    # Send image to roboflow
        rfLabretProject.upload(filePath, tag_names=[id])

    # Get image URL
    # Case 1: When using search_all
    for page in rfLabretProject.search_all(tag=id, batch=True, fields=["id", "owner"]):
        imageIds.extend(page)
    # Case 2: When using search
    for page in rfLabretProject.search(tag=id, batch=True, fields=["id", "owner"]):
        imageIds.append(page)

    return jsonify({'message': 'User registered successfully', 'imageIds': imageIds})

The problem is, I tried using search_all and search functions and set it to check results from batches since I just uploaded them. both search and search_all doesn't return any results: image

I'm not sure whether I specified the right arguments or if the upload result is not immediately available yet

Kyewn commented 3 months ago

When i put search functions in the for (i, image) in enumerate(images): loop, final result show relevant image ids but is inconsistent and different between attempts.

e.g. Here I uploaded 5 images. for loop iterates and appends new result item over upload count, and the latest result show all 5 images, but in another attempt and most cases, I get nothing. image image

I assume upload is async, but I'm new to Python in general and I don't know how to wait for the function.