Dear community and @John6666 ,
I finally updated my dataset mask with end products size (512 x 512 x 3). I was going to follow code as suggested but fell to the same error before I recreate my masks. I ask gpt that I might need to adjust the size of the images but both dataset from the example code (check their dataset here) and mine (check my dataset here) both are 3 dimension but theirs are (1080, 1920, 3) while mine are (512, 512, 3).
Here’s the error, the code is perfectly similar to this tutorial. Is my mask still wrong (it might not be segmentation map, idk what is segmentation map is it not in 3d or is it not a .jpeg image?) or what parameters should I change?
The error
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[59], line 1
----> 1 trainer.train()
File c:\Users\Lenovo\miniconda3\envs\pretrain-huggingface\Lib\site-packages\transformers\trainer.py:2155, in Trainer.train(self, resume_from_checkpoint, trial, ignore_keys_for_eval, **kwargs)
2152 try:
2153 # Disable progress bars when uploading models during checkpoints to avoid polluting stdout
2154 hf_hub_utils.disable_progress_bars()
-> 2155 return inner_training_loop(
2156 args=args,
2157 resume_from_checkpoint=resume_from_checkpoint,
2158 trial=trial,
2159 ignore_keys_for_eval=ignore_keys_for_eval,
2160 )
2161 finally:
2162 hf_hub_utils.enable_progress_bars()
File c:\Users\Lenovo\miniconda3\envs\pretrain-huggingface\Lib\site-packages\transformers\trainer.py:2472, in Trainer._inner_training_loop(self, batch_size, args, resume_from_checkpoint, trial, ignore_keys_for_eval)
2470 update_step += 1
2471 num_batches = args.gradient_accumulation_steps if update_step != (total_updates - 1) else remainder
-> 2472 batch_samples, num_items_in_batch = self.get_batch_samples(epoch_iterator, num_batches)
2473 for i, inputs in enumerate(batch_samples):
2474 step += 1
File c:\Users\Lenovo\miniconda3\envs\pretrain-huggingface\Lib\site-packages\transformers\trainer.py:5131, in Trainer.get_batch_samples(self, epoch_iterator, num_batches)
5129 for _ in range(num_batches):
5130 try:
-> 5131 batch_samples += [next(epoch_iterator)]
5132 except StopIteration:
5133 break
File c:\Users\Lenovo\miniconda3\envs\pretrain-huggingface\Lib\site-packages\accelerate\data_loader.py:552, in DataLoaderShard.__iter__(self)
550 # We iterate one batch ahead to check when we are at the end
551 try:
--> 552 current_batch = next(dataloader_iter)
553 except StopIteration:
554 yield
File c:\Users\Lenovo\miniconda3\envs\pretrain-huggingface\Lib\site-packages\torch\utils\data\dataloader.py:701, in _BaseDataLoaderIter.__next__(self)
698 if self._sampler_iter is None:
699 # TODO(https://github.com/pytorch/pytorch/issues/76750)
700 self._reset() # type: ignore[call-arg]
--> 701 data = self._next_data()
702 self._num_yielded += 1
703 if (
704 self._dataset_kind == _DatasetKind.Iterable
705 and self._IterableDataset_len_called is not None
706 and self._num_yielded > self._IterableDataset_len_called
707 ):
File c:\Users\Lenovo\miniconda3\envs\pretrain-huggingface\Lib\site-packages\torch\utils\data\dataloader.py:757, in _SingleProcessDataLoaderIter._next_data(self)
755 def _next_data(self):
756 index = self._next_index() # may raise StopIteration
--> 757 data = self._dataset_fetcher.fetch(index) # may raise StopIteration
758 if self._pin_memory:
759 data = _utils.pin_memory.pin_memory(data, self._pin_memory_device)
File c:\Users\Lenovo\miniconda3\envs\pretrain-huggingface\Lib\site-packages\torch\utils\data\_utils\fetch.py:50, in _MapDatasetFetcher.fetch(self, possibly_batched_index)
48 if self.auto_collation:
49 if hasattr(self.dataset, "__getitems__") and self.dataset.__getitems__:
---> 50 data = self.dataset.__getitems__(possibly_batched_index)
51 else:
52 data = [self.dataset[idx] for idx in possibly_batched_index]
File c:\Users\Lenovo\miniconda3\envs\pretrain-huggingface\Lib\site-packages\datasets\arrow_dataset.py:2766, in Dataset.__getitems__(self, keys)
2764 def __getitems__(self, keys: List) -> List:
2765 """Can be used to get a batch using a list of integers indices."""
-> 2766 batch = self.__getitem__(keys)
2767 n_examples = len(batch[next(iter(batch))])
2768 return [{col: array[i] for col, array in batch.items()} for i in range(n_examples)]
File c:\Users\Lenovo\miniconda3\envs\pretrain-huggingface\Lib\site-packages\datasets\arrow_dataset.py:2762, in Dataset.__getitem__(self, key)
2760 def __getitem__(self, key): # noqa: F811
2761 """Can be used to index columns (by string names) or rows (by integer index or iterable of indices or bools)."""
-> 2762 return self._getitem(key)
File c:\Users\Lenovo\miniconda3\envs\pretrain-huggingface\Lib\site-packages\datasets\arrow_dataset.py:2747, in Dataset._getitem(self, key, **kwargs)
2745 formatter = get_formatter(format_type, features=self._info.features, **format_kwargs)
2746 pa_subtable = query_table(self._data, key, indices=self._indices)
-> 2747 formatted_output = format_table(
2748 pa_subtable, key, formatter=formatter, format_columns=format_columns, output_all_columns=output_all_columns
2749 )
2750 return formatted_output
File c:\Users\Lenovo\miniconda3\envs\pretrain-huggingface\Lib\site-packages\datasets\formatting\formatting.py:639, in format_table(table, key, formatter, format_columns, output_all_columns)
637 python_formatter = PythonFormatter(features=formatter.features)
638 if format_columns is None:
--> 639 return formatter(pa_table, query_type=query_type)
640 elif query_type == "column":
641 if key in format_columns:
File c:\Users\Lenovo\miniconda3\envs\pretrain-huggingface\Lib\site-packages\datasets\formatting\formatting.py:407, in Formatter.__call__(self, pa_table, query_type)
405 return self.format_column(pa_table)
406 elif query_type == "batch":
--> 407 return self.format_batch(pa_table)
File c:\Users\Lenovo\miniconda3\envs\pretrain-huggingface\Lib\site-packages\datasets\formatting\formatting.py:522, in CustomFormatter.format_batch(self, pa_table)
520 batch = self.python_arrow_extractor().extract_batch(pa_table)
521 batch = self.python_features_decoder.decode_batch(batch)
--> 522 return self.transform(batch)
Cell In[47], line 10, in train_transforms(example_batch)
8 images = [jitter(x) for x in example_batch['pixel_values']]
9 labels = [x for x in example_batch['label']]
---> 10 inputs = feature_extractor(images, labels)
11 return inputs
File c:\Users\Lenovo\miniconda3\envs\pretrain-huggingface\Lib\site-packages\transformers\models\segformer\image_processing_segformer.py:303, in SegformerImageProcessor.__call__(self, images, segmentation_maps, **kwargs)
296 def __call__(self, images, segmentation_maps=None, **kwargs):
297 """
298 Preprocesses a batch of images and optionally segmentation maps.
299
300 Overrides the `__call__` method of the `Preprocessor` class so that both images and segmentation maps can be
301 passed in as positional arguments.
302 """
--> 303 return super().__call__(images, segmentation_maps=segmentation_maps, **kwargs)
File c:\Users\Lenovo\miniconda3\envs\pretrain-huggingface\Lib\site-packages\transformers\image_processing_utils.py:41, in BaseImageProcessor.__call__(self, images, **kwargs)
39 def __call__(self, images, **kwargs) -> BatchFeature:
40 """Preprocess an image or a batch of images."""
---> 41 return self.preprocess(images, **kwargs)
File c:\Users\Lenovo\miniconda3\envs\pretrain-huggingface\Lib\site-packages\transformers\utils\deprecation.py:165, in deprecate_kwarg.<locals>.wrapper.<locals>.wrapped_func(*args, **kwargs)
161 elif minimum_action in (Action.NOTIFY, Action.NOTIFY_ALWAYS):
162 # DeprecationWarning is ignored by default, so we use FutureWarning instead
163 warnings.warn(message, FutureWarning, stacklevel=2)
--> 165 return func(*args, **kwargs)
File c:\Users\Lenovo\miniconda3\envs\pretrain-huggingface\Lib\site-packages\transformers\utils\generic.py:852, in filter_out_non_signature_kwargs.<locals>.decorator.<locals>.wrapper(*args, **kwargs)
843 cls_prefix = ""
845 warnings.warn(
846 f"The following named arguments are not valid for `{cls_prefix}{func.__name__}`"
847 f" and were ignored: {invalid_kwargs_names}",
848 UserWarning,
849 stacklevel=2,
850 )
--> 852 return func(*args, **valid_kwargs)
File c:\Users\Lenovo\miniconda3\envs\pretrain-huggingface\Lib\site-packages\transformers\models\segformer\image_processing_segformer.py:423, in SegformerImageProcessor.preprocess(self, images, segmentation_maps, do_resize, size, resample, do_rescale, rescale_factor, do_normalize, image_mean, image_std, do_reduce_labels, return_tensors, data_format, input_data_format)
420 data = {"pixel_values": images}
422 if segmentation_maps is not None:
--> 423 segmentation_maps = [
424 self._preprocess_mask(
425 segmentation_map=segmentation_map,
426 do_reduce_labels=do_reduce_labels,
427 do_resize=do_resize,
428 size=size,
429 input_data_format=input_data_format,
430 )
431 for segmentation_map in segmentation_maps
432 ]
433 data["labels"] = segmentation_maps
435 return BatchFeature(data=data, tensor_type=return_tensors)
File c:\Users\Lenovo\miniconda3\envs\pretrain-huggingface\Lib\site-packages\transformers\models\segformer\image_processing_segformer.py:424, in <listcomp>(.0)
420 data = {"pixel_values": images}
422 if segmentation_maps is not None:
423 segmentation_maps = [
--> 424 self._preprocess_mask(
425 segmentation_map=segmentation_map,
426 do_reduce_labels=do_reduce_labels,
427 do_resize=do_resize,
428 size=size,
429 input_data_format=input_data_format,
430 )
431 for segmentation_map in segmentation_maps
432 ]
433 data["labels"] = segmentation_maps
435 return BatchFeature(data=data, tensor_type=return_tensors)
File c:\Users\Lenovo\miniconda3\envs\pretrain-huggingface\Lib\site-packages\transformers\models\segformer\image_processing_segformer.py:278, in SegformerImageProcessor._preprocess_mask(self, segmentation_map, do_reduce_labels, do_resize, size, input_data_format)
276 added_channel_dim = False
277 if input_data_format is None:
--> 278 input_data_format = infer_channel_dimension_format(segmentation_map, num_channels=1)
279 # reduce zero label if needed
280 segmentation_map = self._preprocess(
281 image=segmentation_map,
282 do_reduce_labels=do_reduce_labels,
(...)
288 input_data_format=input_data_format,
289 )
File c:\Users\Lenovo\miniconda3\envs\pretrain-huggingface\Lib\site-packages\transformers\image_utils.py:255, in infer_channel_dimension_format(image, num_channels)
253 elif image.shape[last_dim] in num_channels:
254 return ChannelDimension.LAST
--> 255 raise ValueError("Unable to infer channel dimension format")
ValueError: Unable to infer channel dimension format
I have checked this]([Error] Unable to infer channel dimension format) but from that size I think both, image and the label, has similar size and dimension already.
Thanks in advance