fathomnet / fathomnet-py

FathomNet Python client
https://fathomnet-py.readthedocs.io
MIT License
29 stars 3 forks source link

Error when trying to retrieve COCO annotations for some species #10

Closed mi2celis closed 2 years ago

mi2celis commented 2 years ago

I am trying to download COCO annotations for certain species using fathomnet-generate.

For certain species, I have no errors, e.g. fathomnet-generate -c "Sebastes auriculatus" --format coco -o Sebastes_auriculatus

However, for others I have tried (Sebastes, Anoplopoma fimbria, Sebastolobus, Dosidicus gigas, Gonatus onyx, Chiroteuthis calyx, Nanomia bijuga) I get errors.

For example: $ fathomnet-generate -c "Sebastes" --format coco -o Sebastes Traceback (most recent call last): File "/home/mimi/.local/bin/fathomnet-generate", line 11, in sys.exit(main()) File "/home/mimi/.local/lib/python3.7/site-packages/fathomnet/scripts/fathomnet_generate.py", line 426, in main error = generate_dataset(args, dataset_images) # Generate the dataset File "/home/mimi/.local/lib/python3.7/site-packages/fathomnet/scripts/fathomnet_generate.py", line 234, in generate_dataset return dataset_func[args.format](ims, args.output) File "/home/mimi/.local/lib/python3.7/site-packages/fathomnet/scripts/fathomnet_generate.py", line 218, in generate_coco_dataset coco_dataset.save(output_path, indent=2) File "/home/mimi/.local/lib/python3.7/site-packages/coco_lib/bases.py", line 21, in save f.write(self.to_json(**kwargs)) File "/home/mimi/.local/lib/python3.7/site-packages/dataclasses_json/api.py", line 49, in to_json return json.dumps(self.to_dict(encode_json=False), File "/home/mimi/.local/lib/python3.7/site-packages/dataclasses_json/api.py", line 85, in to_dict return _asdict(self, encode_json=encode_json) File "/home/mimi/.local/lib/python3.7/site-packages/dataclasses_json/core.py", line 340, in _asdict encode_json=encode_json File "/home/mimi/.local/lib/python3.7/site-packages/dataclasses_json/core.py", line 354, in _asdict return list(_asdict(v, encode_json=encode_json) for v in obj) File "/home/mimi/.local/lib/python3.7/site-packages/dataclasses_json/core.py", line 354, in return list(_asdict(v, encode_json=encode_json) for v in obj) File "/home/mimi/.local/lib/python3.7/site-packages/dataclasses_json/core.py", line 347, in _asdict encode_json=encode_json) File "/home/mimi/.local/lib/python3.7/site-packages/dataclasses_json/core.py", line 110, in _encode_overrides v = encoder(v) if encoder is not None else v File "/home/mimi/.local/lib/python3.7/site-packages/coco_lib/common.py", line 37, in encoder=lambda d: d.strftime('%Y-%m-%d %H:%M:%S'), AttributeError: 'NoneType' object has no attribute 'strftime'

Any suggestions?

kevinsbarnard commented 2 years ago

Confirmed. Looking into this now.

kevinsbarnard commented 2 years ago

The bug was in one of fathomnet-py's dependencies: coco-lib; images with missing timestamps were failing to serialize into the COCO format.

Fixed in coco-lib v0.1.2 and fathomnet-py v0.5.0.

Tested with command:

fathomnet-generate --concepts "Sebastes,Anoplopoma fimbria,Sebastolobus,Dosidicus gigas,Gonatus onyx,Chiroteuthis calyx,Nanomia bijuga" --format coco -o test_dataset -v
mi2celis commented 2 years ago

How do I update to coco-lib v0.1.2 andf athomnet-py v0.5.0 Will a simple pip install pull the updated versions?

kevinsbarnard commented 2 years ago

Yes, running:

pip install --upgrade fathomnet

will upgrade both.

mi2celis commented 2 years ago

Ran into a different problem after upgrading:

$ fathomnet-generate --concepts "Sebastes,Anoplopoma fimbria,Sebastolobus,Dosidicus gigas,Gonatus onyx,Chiroteuthis calyx,Nanomia bijuga" --format coco -o fish_squid_species

Traceback (most recent call last): File "/home/mimi/.local/bin/fathomnet-generate", line 7, in from fathomnet.scripts.fathomnet_generate import main File "/home/mimi/.local/lib/python3.7/site-packages/fathomnet/scripts/fathomnet_generate.py", line 63, in def download_imgs(args: Arguments, ims: list[AImageDTO]): TypeError: 'type' object is not subscriptable

kevinsbarnard commented 2 years ago

Fixed in v0.5.1. This bug was present only in Python 3.7.

mi2celis commented 2 years ago

Everything is working now. Thank you!