cvat: Dataset Upload Error (Using the API)

My actions before raising this issue

  • [x ] Read/searched the docs
  • [x ] Searched past issues

I am trying to upload a dataset using the python API

My python version 3.10.11 CVAT version: 2.5

My directory structure looks like this


├── training_1
│   ├── image_2 (n images)
│   └── label_2 (n labels) 
├── training_1.zip (a zip archive of the training_1 directory)
├── test.ipynb (notebook running the code I have listed below)

First I read the documentation at https://opencv.github.io/cvat/docs/api_sdk/sdk/reference/apis/projects-api/ to write the following code

from pprint import pprint
from cvat_sdk.api_client import Configuration, ApiClient, models, apis, exceptions 
from cvat_sdk.api_client.models import *


configuration = Configuration(
    host = "http://cvat.gnet.local:8080",
    username = "test",       # credentials used to login to cvat web
    password = "test_pw"
)

with ApiClient(configuration) as api_client:
    id = 1
    filename = "./training_1.zip"
    format = "KITTI 1.0"
    location = "local"
    use_default_location = True
    dataset_write_request = DatasetWriteRequest(None)

    try:
        (data, response) = api_client.projects_api.create_dataset(
            id,
            filename=filename,
            format=format,
            location=location,
            use_default_location=use_default_location,
            dataset_write_request=dataset_write_request
        )

        pprint(data)
    except exceptions.ApiException as e:
        print("Exception when calling ProjectsApi.create_dataset: %s\n" % e)

I got back:

Exception when calling ProjectsApi.create_dataset: Status Code: 404
Reason: Not Found
HTTP response headers: HTTPHeaderDict({'Allow': 'GET, POST, HEAD, OPTIONS', 'Content-Length': '23', 'Content-Type': 'application/vnd.cvat+json', 'Cross-Origin-Opener-Policy': 'same-origin', 'Date': 'Wed, 19 Jul 2023 15:20:09 GMT', 'Referrer-Policy': 'same-origin', 'Server': 'nginx/1.18.0 (Ubuntu)', 'Vary': 'Accept, Origin, Cookie', 'X-Content-Type-Options': 'nosniff', 'X-Frame-Options': 'DENY', 'X-Request-Id': 'b8de57ef-1bb4-4774-beb1-38cade4449ef'})
HTTP response body: {"detail":"Not found."}

Then I also tried with rest API calls

created a session object

import requests
import json
session  = requests.Session() # create a session object
host_url = "http://cvat.gnet.local:8080"

then I tried login

base_url = f"{host_url}/auth/login"
login_data = {"username": "test",  "email": "test@testmail.com" ,"password": "test_pw"}
headers = {"accept": "application/vnd.cvat+json", "Content-Type": "application/json", } 
response = session.post(base_url, data=json.dumps(login_data), headers=headers)

# Print status code and response text
print(f'Status code: {response.status_code}')
print(f'Response text: {response.text}')
print(f'CSRF token: {session.cookies["csrftoken"]}')

login worked (AFIK)

Status code: 200
Response text: {"key":"59175d8ceea31e384b592a77f435e4361b41704c"}
CSRF token: jpxPp8oDAzrLpte1EkeAbxBuNut9RGNW

Then I tried to upload the dataset again


import requests
import json

# Define the URL, headers and data
url = f'{host_url}/projects/1/dataset/?filename=%22test%22&format=KITTI%201.0&location=local&use_default_location=true'
headers = {
    'accept': '*/*',
    'Content-Type': 'application/json',
    'X-CSRFTOKEN': f'{session.cookies["csrftoken"]}',
    "Authorization": f"Token {token}"
    
}
data = {
    'dataset_file': 'training_1.zip',
}

# Make the POST request
response = session.post(url, headers=headers, data=json.dumps(data))

# Print status code and response text
print(f'Status code: {response.status_code}')
print(f'Response text: {response.text}')
# prinnt xcrf token
print(f'X-CSRFTOKEN: {session.cookies["csrftoken"]}')

# Print the full request
print(f'Request method: {response.request.method}')
print(f'Request URL: {response.request.url}')
print(f'Request headers: {response.request.headers}')
print(f'Request body: {response.request.body}')



I got another error

Status code: 404
Response text: {"detail":"Not found."}
X-CSRFTOKEN: Q7e8Ec4QwZFPsTNypesO10lvQMYxi8vG
Request method: POST
Request URL: http://cvat.qnap.gnet:8080/api/projects/1/dataset/?filename=%22test%22&format=KITTI%201.0&location=local&use_default_location=true
Request headers: {'User-Agent': 'python-requests/2.28.2', 'Accept-Encoding': 'gzip, deflate', 'accept': '*/*', 'Connection': 'keep-alive', 'Content-Type': 'application/json', 'X-CSRFTOKEN': 'Q7e8Ec4QwZFPsTNypesO10lvQMYxi8vG', 'Authorization': 'Token 59175d8ceea31e384b592a77f435e4361b41704c', 'Cookie': 'csrftoken=Q7e8Ec4QwZFPsTNypesO10lvQMYxi8vG; sessionid=56nf7uz9q4qtfgdnhgl7cr4n0q5k4v1k', 'Content-Length': '34'}
Request body: {"dataset_file": "training_1.zip"}

Expected Behaviour

Dataset being uploaded

Am I doing anything wrong here? I also tried creating a dataset by using https://opencv.github.io/cvat/docs/api_sdk/sdk/reference/apis/projects-api/#example but it failed too (maybe the example is outdated)

Cheers, Ganindu.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 20 (7 by maintainers)

Most upvoted comments

Cheers,

  • I updated the repo; now at (2896bec3d4f19b392d24e8119ff085793a550b34) confirmed with git rev-parse HEAD

  • Cleaned up the images docker images -q | xargs docker rmi

  • Set up envs export CVAT_HOST=my.local.cvat.hostpath and docker-compose overrides to point to storage

  • Rebuilt and launched with docker compose up -d --build

set up some extra debugging

312         url = self._client.api_map.make_endpoint_url(upload_endpoint.path, kwsub=url_params)
313         params = {"format": format_name, "filename": filename.name}
314         response = self.upload_file(
315             url, filename, pbar=pbar, query_params=params, meta={"filename": params["filename"]}
316         )
317         print(f"DEBUG: response status_code = {response.status}")
318         print(f"DEBUG: response reason = {response.reason}")
319         print(f"DEBUG: response headers = {response.headers}")
320         print(f"DEBUG: response data = {response.data}")

Confirmed the issue is fixed wit the output!

DEBUG: response status_code = 202
DEBUG: response reason = Accepted
DEBUG: response headers = HTTPHeaderDict({'Allow': 'GET, POST, HEAD, OPTIONS', 'Content-Length': '47', 'Content-Type': 'application/vnd.cvat+json', 'Cross-Origin-Opener-Policy': 'same-origin', 'Date': 'Mon, 24 Jul 2023 12:06:11 GMT', 'Referrer-Policy': 'same-origin', 'Server': 'nginx/1.18.0 (Ubuntu)', 'Vary': 'Accept, Origin', 'X-Content-Type-Options': 'nosniff', 'X-Frame-Options': 'DENY', 'X-Request-Id': '7bf391c6-6474-4599-80fa-5f4a05264607'})
DEBUG: response data = b'{"rq_id":"import:project-3-dataset-by-ganindu"}'

Thanks a lot Maxim!!

Best, Ganindu.

If there is no rq_id in the reply and the status is 202, then the server is probably using some older version. The rq_id response was added in https://github.com/opencv/cvat/pull/5909.

Can I use “KITTI 1.0” as the dataset_format?

Sure, please check the uploaded file uses the file layout described here.

As I’m using the KITTI 1.0 format (and as I’ve shown above) dataset_path can I use the local path to the .zip archive?

Yes, this is the default option in high-level SDK.