- 
                Notifications
    
You must be signed in to change notification settings  - Fork 22
 
Closed
Description
Hi! I'm trying to export a model specifying the pixel size but whenever it's different from 1 or 0.5, it gives the following error. The variable pixel size enters as  {'x': 0.8, 'y': 0.8, 'z': 0.005} in the kwargs of the build_model.
I'm trying it with the 3D UNet notebook of ZeroCostDL4Mic using TF 2.11 (I will update the notebook now in their repo)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/usr/local/lib/python3.8/dist-packages/tifffile/tifffile.py in enumarg(enum, arg)
  22897     try:
> 22898         return enum(arg)  # type: ignore
  22899     except Exception:
9 frames
[/usr/lib/python3.8/enum.py](https://localhost:8080/#) in __call__(cls, value, names, module, qualname, type, start)
    338         if names is None:  # simple value lookup
--> 339             return cls.__new__(cls, value)
    340         # otherwise, functional API: we're creating a new Enum type
[/usr/lib/python3.8/enum.py](https://localhost:8080/#) in __new__(cls, value)
    662                 if result is None and exc is None:
--> 663                     raise ve_exc
    664                 elif exc is None:
ValueError: 20.0 is not a valid RESUNIT
During handling of the above exception, another exception occurred:
AttributeError                            Traceback (most recent call last)
/usr/local/lib/python3.8/dist-packages/tifffile/tifffile.py in enumarg(enum, arg)
  22900         try:
> 22901             return enum[arg.upper()]  # type: ignore
  22902         except Exception:
AttributeError: 'float' object has no attribute 'upper'
During handling of the above exception, another exception occurred:
ValueError                                Traceback (most recent call last)
[<ipython-input-51-bcabd10cff2c>](https://localhost:8080/#) in <module>
    203 
    204 # export the model with keras weihgts
--> 205 build_model(
    206     weight_uri=weight_path,
    207     test_inputs=[test_in_path],
[/usr/local/lib/python3.8/dist-packages/bioimageio/core/build_spec/build_model.py](https://localhost:8080/#) in build_model(weight_uri, test_inputs, test_outputs, input_axes, output_axes, name, description, authors, tags, documentation, cite, output_path, architecture, model_kwargs, weight_type, sample_inputs, sample_outputs, input_names, input_step, input_min_shape, input_data_range, output_names, output_reference, output_scale, output_offset, output_data_range, halo, preprocessing, postprocessing, pixel_sizes, maintainers, license, covers, git_repo, attachments, packaged_by, run_mode, parent, config, dependencies, links, training_data, root, add_deepimagej_config, tensorflow_version, opset_version, pytorch_version, weight_attachments)
    830     if add_deepimagej_config:
    831         if sample_inputs is None:
--> 832             sample_inputs, sample_outputs = _write_sample_data(
    833                 test_inputs, test_outputs, input_axes, output_axes, pixel_sizes, root
    834             )
[/usr/local/lib/python3.8/dist-packages/bioimageio/core/build_spec/build_model.py](https://localhost:8080/#) in _write_sample_data(input_paths, output_paths, input_axes, output_axes, pixel_sizes, export_folder)
    452         sample_in_path = export_folder / f"sample_input_{i}.tif"
    453         pixel_size = None if pixel_sizes is None else pixel_sizes[i]
--> 454         write_im(sample_in_path, inp, axes, pixel_size)
    455         sample_in_paths.append(sample_in_path)
    456 
[/usr/local/lib/python3.8/dist-packages/bioimageio/core/build_spec/build_model.py](https://localhost:8080/#) in write_im(path, im, axes, pixel_size)
    445         if np.dtype(im.dtype) == np.dtype("float64"):
    446             im = im.astype("float32")
--> 447         tifffile.imwrite(path, im, imagej=True, resolution=resolution)
    448 
    449     sample_in_paths = []
[/usr/local/lib/python3.8/dist-packages/tifffile/tifffile.py](https://localhost:8080/#) in imwrite(file, data, bigtiff, byteorder, imagej, ome, shaped, append, shape, dtype, photometric, planarconfig, extrasamples, volumetric, tile, rowsperstrip, bitspersample, compression, compressionargs, predictor, subsampling, jpegtables, colormap, description, datetime, resolution, resolutionunit, subfiletype, software, metadata, extratags, contiguous, truncate, align, maxworkers, returnoffset)
   1209         shaped=shaped,
   1210     ) as tif:
-> 1211         result = tif.write(
   1212             data,
   1213             shape=shape,
[/usr/local/lib/python3.8/dist-packages/tifffile/tifffile.py](https://localhost:8080/#) in write(***failed resolving arguments***)
   2800                 unit = resolution[2]  # type: ignore
   2801                 if unit is not None:
-> 2802                     resolutionunit = enumarg(RESUNIT, unit)
   2803             addtag(tags, 296, 3, 1, resolutionunit)  # ResolutionUnit
   2804         else:
/usr/local/lib/python3.8/dist-packages/tifffile/tifffile.py in enumarg(enum, arg)
  22901             return enum[arg.upper()]  # type: ignore
  22902         except Exception:
> 22903             raise ValueError(f'invalid argument {arg!r}')
  22904 
  22905 
ValueError: invalid argument 20.0tifffile has changed some parameters of imwrite in their last version so it may be that they also have some requirements for the resolution variable.
| tifffile.imwrite(path, im, imagej=True, resolution=resolution) | 
Metadata
Metadata
Assignees
Labels
No labels