Closed melisande-c closed 3 months ago
Thank you @melisande-c for reporting this issue!
The error seems to result from implicitly reusing parts of the default ValidationContext
, which is a bug indeed.
A workaround could be to provide a ValidationContext
explicitly:
from bioimageio.spec import ValidationContext
for work_dir in work_dirs:
...
# export to BMZ
with ValidationContext(): # avoid bug where parts of the default `ValidationContext` are being reused ('known_files' in particular)
careamist.export_to_bmz(
path=work_dir / "model.zip",
name="TopModel",
input_array=train_array,
authors=[{"name": "Amod", "affiliation": "El"}],
general_description="A model that just walked in.",
)
I'll fix the bug in a future release.
should be fixed in bioimageio-spec==0.5.3.2, please reopen if not
This seems to be working now, thanks!
Hi, the CAREamics library has been experiencing an issue with the spec library in version 0.5.3 (0.5.2 works fine).
The problem arises when our
careamics.model_io.export_to_bmz
function, that in turn calls thesave_bioimage_package
, function is called twice. This is also causing all our tests that export to bmz to fail.Code snippet The following code snippet will recreate the behaviour, with package versions:
careamics==0.1.0rc9
bioimageio-spec==0.5.3.1
bioimageio-core==0.6.8
This results in the error:
As you can see there is a SHA256 mismatch. The second time the train + export pipeline is run the outputs.npy file has the hash
cfda823cc73938b05d19fc70e10c59ef0f0ca770eafb7cb223c8afee227c3e4a
but it is attempting to compare it with the hash of the first outputs.npy file which is0eb281eb5573edb034ce946c6b2ad8b083868d42e058a825411900928cb60651
.This is also the issue with the sha mismatch with the weights. Strangely in the careamics tests this error is raised for the inputs.npy file but it does not seem to be a problem in this example.
Summary of
careamics.model_io.export_to_bmz
Quick walkthrough of what happens in the
careamics.model_io.export_to_bmz
function is as follows: 1) A temporary directory is created using python's built-in packagetempfile
(in the above example the first directory made is /tmp/tmpdvbxmckt/ and the second is /tmp/tmpxz5d0q4j/). 2) The environment.yml file, the inputs.npy file, the outputs.npy file, the config.yml file, and the pytorch state dict file — weights.pth are saved in this temporary directory. 3) TheModelDesc
object is created by first creating theInputTensorDesc
,OutputTensorDesc
,ArchitectureFromLibraryDescr
andWeightsDescr
objects. 4) Thesave_bioimageio_package
function is called using the just createdModelDesc
.