Boolean tensors for input and output of cnn classifier

Hello! I am relatively new to PyTorch. I want to train a convolutional neural network regression model, which should have both the input and output as boolean tensors. I followed the classifier example on PyTorch tutorials (Training a Classifier — PyTorch Tutorials 1.9.0+cu102 documentation). In the “forward” method in the “Net” class, I believe the input “x” has to be of type tensor.float32 because when I define x as type tensor.float32, the code runs fine, but when I change the type of x to tensor.bool (which is the correct type for the data that I have), I get an error for the line “self.conv1 = nn.Conv3d(3, 6, 5)”

“RuntimeError: “addmm_impl_cpu_” not implemented for ‘Bool’”

Can someone please help me with this error? Plus, if I want a boolean tensors as input and output of my network, can I just do it by passing “x” as a boolean tensor in the PyTorch’s classifier example?

You won’t be able to use the bool data type directly, as the parameters are defined as floating point types. Integer types (or bool in this case) could be used via quantization approaches, but I’m unsure if that’s really what you would like to achieve.
Could you describe the use case a bit and in particular, why the bool input and output would be needed or if you could transform the inputs to float32 and apply a threshold to get the desired target labels (assuming the bool output represents classes or a similar output)?

Thank for your answer, ptrblck! I am using the CNN for my work in Chemistry, and the use case goes as follows:
For the I/O of the CNN, I use 3D tensors. These 3D tensors are the grid representations of the chemical molecules I want to train my network with. I initiate the 3D tensor with all zero values, and update a grid’s value to 1 if an atom (of the molecule) is present in the grid. The grid resolution is small enough such that there can only be maximum one atom in a particular grid. That is how I end up with a 3D tensor, that has values only 0 (grid in which no atom is present) and 1 (grid where 1 atom is present).

An analogy of this problem can be that, imagine if you have to train a CNN using a collection of black-and-white images. These images have pixel values either 0 or 1.

Thanks for the update. Your use case sounds indeed like using images with black and while pixel values, so you should be able to transform it to float32 in the input.
I’m currently still unsure how the output would be treated, i.e. are you using the bool output to classify each pixel location or to restore the original input? In that case also the output could be converted to float32.