DIAGNijmegen / rse-gcapi

Python client for the grand-challenge.org API
Apache License 2.0
2 stars 3 forks source link

client.py, 'str' object has no attribute 'name' #120

Closed snorthman closed 2 years ago

snorthman commented 2 years ago

Description

Following the tutorial on the grand challenge website trying to upload my hoard of .mha files, I get the following error

File "~\gcapi\client.py", line 572, in _upload_files
    fileobj=f, filename=file.name
AttributeError: 'str' object has no attribute 'name'

What I Did

Using ravpn.radboudumc.nl

cd /media/pelvis/projects/stan/ && ./gc.sh

See /media/pelvis/projects/stan/grandchallenge.py for my code

jmsmkn commented 2 years ago

When creating issues please include code snippets to reproduce the problem. I cannot see files on your local /media/ mount.

snorthman commented 2 years ago

Excuse me.

    client = gcapi.Client(token=args.gc_api)

    files = {}
    # Loop through files in the specified directory and add their names to the list
    for root, directories, filenames in os.walk(args.input):
        for direc in directories:
            temp = []
            for file in os.listdir(os.path.join(root, direc)):
                temp.append(os.path.join(root, direc, file))
            files[direc] = temp
    print("Found", len(files.keys()), "cases for upload")

    sessions = []
    for i, key in enumerate(files.keys(), 1):
        try:
            temp_session = client.upload_cases(files=files[key], reader_study=args.slug)
            sessions.append(temp_session)
            print(files[key])
            print("Uploaded session", i, "of", len(files.keys()))
        except Exception as e:
            print(f"files[key]={files[key]}")
            traceback.print_exc()
            sys.exit(1)

where

args.input is /media/pelvis/data/prostate-MRI/rumc/needle args.gc_api is a valid API from grandchallenge args.slug is needle-segmentation-for-interventional-radiology (a reader study)

jmsmkn commented 2 years ago

Again, I cannot access things on your /media/ mount. Please provide a code snippet that I can run that reproduces this problem as I cannot.

snorthman commented 2 years ago
import gcapi
import os, sys, argparse, traceback

file = os.path.abspath("path/to/file.mha")
gc_api = "api"
client = gcapi.Client(token=gc_api)
client.upload_cases(files=[file], reader_study="needle-segmentation-for-interventional-radiology")

It also breaks with arbitrary files, such as a .txt, so to reproduce a .mha file is not necessary.

Kicksta commented 2 years ago

+1, I just ran into the same problem following the tutorial.

jmsmkn commented 2 years ago

Replace os.path.abspath with pathlib.Path.