stardist / stardist

StarDist - Object Detection with Star-convex Shapes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot run a training because of the name

I-Guy opened this issue · comments

Describe the bug
Hi,
first, thank you for Stardist!
I got a bug with the training, I am using the tutorial with my own data, but when I have to train the model, it threw this error :

ValueError                                Traceback (most recent call last)
Cell In[11], line 1
----> 1 model.train(X_trn, Y_trn, validation_data=(X_val,Y_val))

File ~/miniconda3/lib/python3.11/site-packages/stardist/models/model2d.py:405, in StarDist2D.train(self, X, Y, validation_data, classes, augmenter, seed, epochs, steps_per_epoch, workers)
    399 [(p-2*b) % d == 0 or _raise(ValueError(
    400     "'train_patch_size' - 2*'train_completion_crop' must be divisible by {d} along axis '{a}'".format(a=a,d=d) if self.config.train_shape_completion else
    401     "'train_patch_size' must be divisible by {d} along axis '{a}'".format(a=a,d=d)
    402  )) for p,d,a in zip(patch_size,div_by,axes)]
    404 if not self._model_prepared:
--> 405     self.prepare_for_training()
    407 data_kwargs = dict (
    408     n_rays           = self.config.n_rays,
    409     patch_size       = self.config.train_patch_size,
   (...)
    416     sample_ind_cache = self.config.train_sample_cache,
    417 )
    419 # generate validation data and store in numpy arrays

File ~/miniconda3/lib/python3.11/site-packages/stardist/models/base.py:342, in StarDistBase.prepare_for_training(self, optimizer)
    340 self.callbacks = []
    341 if self.basedir is not None:
--> 342     self.callbacks += self._checkpoint_callbacks()
    344     if self.config.train_tensorboard:
    345         if IS_TF_1:

File ~/miniconda3/lib/python3.11/site-packages/csbdeep/models/base_model.py:194, in BaseModel._checkpoint_callbacks(self)
    192 ModelCheckpoint = keras_import('callbacks', 'ModelCheckpoint')
    193 if self.config.train_checkpoint is not None:
--> 194     callbacks.append(ModelCheckpoint(str(self.logdir / self.config.train_checkpoint),       save_best_only=True,  save_weights_only=True))
    195 if self.config.train_checkpoint_epoch is not None:
    196     callbacks.append(ModelCheckpoint(str(self.logdir / self.config.train_checkpoint_epoch), save_best_only=False, save_weights_only=True))

File ~/miniconda3/lib/python3.11/site-packages/keras/src/callbacks/model_checkpoint.py:183, in ModelCheckpoint.__init__(self, filepath, monitor, verbose, save_best_only, save_weights_only, mode, save_freq, initial_value_threshold)
    181 if save_weights_only:
    182     if not self.filepath.endswith(".weights.h5"):
--> 183         raise ValueError(
    184             "When using `save_weights_only=True` in `ModelCheckpoint`"
    185             ", the filepath provided must end in `.weights.h5` "
    186             "(Keras weights format). Received: "
    187             f"filepath={self.filepath}"
    188         )
    189 else:
    190     if not self.filepath.endswith(".keras"):

ValueError: When using `save_weights_only=True` in `ModelCheckpoint`, the filepath provided must end in `.weights.h5` (Keras weights format). Received: filepath=models/stardist_lebatard/weights_best.h5


To reproduce
Basic tutorial for training model : https://github.com/stardist/stardist/blob/master/examples/2D/2_training.ipynb
I tried with different version of stardist from (0.80 to 0.85)

Expected behavior
I expect the command to train the model

Environment (please complete the following information):
os: Linux-6.5.0-26-generic-x86_64-with-glibc2.38
stardist: 0.8.5
csbdeep: 0.7.4
tensorflow: 2.16.1
WARNING:tensorflow:From /tmp/ipykernel_292456/1014409130.py:12: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.config.list_physical_devices('GPU') instead.
tensorflow GPU: False

Do you have any solution to solve it ? Thank you for your time.

IGuy

Hi everyone,
it seems like the bug came from Keras, after downgrading it to an older version.
All seems to work !

IGuy

We've released StarDist 0.9.0, which now support Keras 3 and TensorFlow 2.16+.