Unsupported upperand error when using OrdinalCrossEntropy
ThomasPel1 opened this issue · 4 comments
I run the following (very basic) code:
import coral_ordinal as coral
model = keras.Sequential()
model.add(keras.layers.Dense(32, activation = "relu"))
model.add(coral.CoralOrdinal(num_classes = 5)) # Ordinal variable has 5 labels, 0 through 4.
model.compile(loss = coral.OrdinalCrossEntropy(), metrics = [coral.MeanAbsoluteErrorLabels])
And get the following error:
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'
This error originates in coral.OrdinalCrossEntropy(), see traceback:
` in
3 model.add(keras.layers.Dense(32, activation = "relu"))
4 model.add(coral.CoralOrdinal(num_classes = 5)) # Ordinal variable has 5 labels, 0 through 4.
----> 5 model.compile(loss = coral.OrdinalCrossEntropy(), metrics = [coral.MeanAbsoluteErrorLabels])
~\Anaconda3\lib\site-packages\coral_ordinal\loss.py in init(self, num_classes, importance, from_type, name, **kwargs)
28 #self.importance_weights = importance
29 if importance is None:
---> 30 self.importance_weights = tf.ones(self.num_classes - 1, dtype = tf.float32)
31 else:
32 self.importance_weights = tf.cast(importance, dtype = tf.float32)`
I am using Tensorflow 2.4.1 and numpy 1.19.5 and python 3.8.5 so based on the requirements it should work. What could cause this problem?
Hello,
Thanks for giving the module a try. As noted in the sentence above that code, there needs to be an input added to the model. That example doesn't have any data so it's just showing what the steps to use it would be in general.
I recommend reviewing this colab notebook where there is data included, esp. the "simple mlp model" section: https://colab.research.google.com/drive/1AQl4XeqRRhd7l30bmgLVObKt5RFPHttn
Let me know if you run into more problems though.
Thanks,
Chris
Also, I would make sure to use the GitHub version of the package (if you aren't already) rather than the pypi version, since the pypi version is unfortunately outdated.
Cheers,
Chris
Thanks you Chris! Changing to the GitHub version solved my problems :)
Glad to hear it! I'll be interested to hear how your research turns out, maybe you can post an update sometime in the future when you're ready?