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)
Cheers,
I updated the repo; now at (
2896bec3d4f19b392d24e8119ff085793a550b34) confirmed withgit rev-parse HEADCleaned up the images
docker images -q | xargs docker rmiSet up envs
export CVAT_HOST=my.local.cvat.hostpathand docker-compose overrides to point to storageRebuilt and launched with
docker compose up -d --buildset up some extra debugging
Confirmed the issue is fixed wit the output!
Thanks a lot Maxim!!
Best, Ganindu.
If there is no
rq_idin 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.Sure, please check the uploaded file uses the file layout described here.
Yes, this is the default option in high-level SDK.