Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shape mismatch at the output on unet when n_classes > 1 #317

Closed
hvgazula opened this issue Apr 2, 2024 · 4 comments
Closed

Shape mismatch at the output on unet when n_classes > 1 #317

hvgazula opened this issue Apr 2, 2024 · 4 comments
Assignees
Labels
Milestone

Comments

@hvgazula
Copy link
Contributor

hvgazula commented Apr 2, 2024

    ValueError: Dimensions must be equal, but are 6 and 256 for '{{node dice/mul}} = Mul[T=DT_FLOAT](IteratorGetNext:1, unet/activation_14/Softmax)' with input shapes: [1,256,256,256,6,6], [1,256,256,256,6].
@hvgazula hvgazula added the bug label Apr 2, 2024
@hvgazula hvgazula self-assigned this Apr 2, 2024
@hvgazula hvgazula added this to the 1.2.1 milestone Apr 2, 2024
@hvgazula
Copy link
Contributor Author

hvgazula commented Apr 2, 2024

shape of labels coming from tfrecords is already (*volume_shape, n_classes). see below

<_TakeDataset element_spec=(TensorSpec(shape=(1, 256, 256, 256, 1), dtype=tf.float32, name=None), TensorSpec(shape=(1, 256, 256, 256, 2), dtype=tf.float32, name=None))>

doing OHE in map_labels again leads to a shape mismatch (an extra dimension is appended, see below).

<_TakeDataset element_spec=(TensorSpec(shape=(1, 256, 256, 256, 1), dtype=tf.float32, name=None), TensorSpec(shape=(1, 256, 256, 256, 2, 2), dtype=tf.float32, name=None))>

Solution: The shape of labels should be (*volume_shape, 1)` until the dataset construction at which point, the n_classes should be factored in.

TODO: This should help address test for n_classes > 1

@hvgazula
Copy link
Contributor Author

hvgazula commented Apr 2, 2024

Reason: map_labels is being called twice.

https://github.com/neuronets/nobrainer_training_scripts/blob/8720c578a624c063373c7c7c14ad339b50b99117/1.2.0/brainy_train.py#L181

if we have to pass on the 6/50 class label mapping (dict), it will become

dataset_train.map_labels(label_mapping).shuffle(NUM_GPUS).. but this mapping is already happening once inside (of course without the label_mapping. We need to pass the label mapping dictionary in a cleaner manner. Where do you think we should do this?

@hvgazula
Copy link
Contributor Author

hvgazula commented Apr 2, 2024

Proposal: add argument label_mapping: Dict = None to both from_files and from_tfrecords in Dataset.

For reference: see https://github.com/neuronets/nobrainer_training_scripts/blob/main/1.2.0/label_mapping.py

@satra 👍 or 👎 ?

@satra
Copy link
Contributor

satra commented Apr 2, 2024 via email

hvgazula added a commit that referenced this issue Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants