Body: <p>Classification: binary</p>
  <p>Model: CNN (ResNet50V2)</p>
  <p>During our research we've had <strong>91x109x91</strong> images (3-dimensional). We've used 2D CNN to train and evaluate our images and make predictions on labelled cases, thus we had to convert 3D to 2D this way (<strong>slices (n*x), y, z, #color_channels</strong>):</p>
  <pre><code>maindata = maindata.reshape(n * 91, 109, 91, 3)
  </code></pre>
  <p>What we did here effectively is merge a number of images (n) with dimension x (in our case 91). So we basically trained our model on slices (2D images) of this 3D image. Thus far everything was good. We've received great results.</p>
  <p>However, now we need to create prediction probabilities of n images (3D images) and not n x 91 slices (2D images).
  Can we take the prediction probabilities we've received (2D) and for every 91 prediction probabilities calculate the mean or is there a better way of interpreting 2D results to 3D images?</p>
  <p>Both train (labelled) and test (unlabelled) data are shaped the same way, so the only part missing is interpretation to 3D.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-03-20T11:51:54.417Z
Comments.Text: two questions: you say you have images of size 91x109x91 but then you say you reshaped them this way (n * 91, 109, 91, 3), introducing channels, so are your images normal 3d images or 4d? Also it's not clear to me why did you have to reshape to 2d? 2d convolutions don't need reshaping, it's called 2d only cause the kernel move along the x and y axis (2d) but the kernel can be 3d, actually that's the standard procedure when processing images.
Comments.UserDisplayName: Edoardo Guerriero
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-03-20T12:05:38.530Z
Comments.Text: We were unable to find Conv3D in Tensorflow library (https://www.tensorflow.org/api_docs/python/tf/keras/applications/resnet).
  Answer to questions:
  1. I have an array of 3D images (4 dimensions), I need to rescale the dimensions to 2D for each image in order to use any of the Conv2D they use (Tensorflow). 
  2. Keras models only support 4 parameters, that is (#images, x, y, #color channels), not the depth dimension(z axis) that we would require.
Comments.UserDisplayName: Amadej Šenk
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-03-20T12:21:09.180Z
Comments.Text: Sorry but I'm still confused cause saying 3D images with 4 dimensions is a contradiction. You talk about depth, is that the extra 4th dimension you have along with the 3D RGB image? Or is the 4th dimension just the batch size?
Comments.UserDisplayName: Edoardo Guerriero
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-03-20T12:22:11.597Z
Comments.Text: Moreover if i look at the documentation of [resnet50](https://www.tensorflow.org/api_docs/python/tf/keras/applications/resnet50/ResNet50) they explicitly write the allowed input dimension, either (224, 224, 3) or (3, 224, 224), which follow the standard resnet paper architecture. So again I don't see why is necessary to reshape your input images. Unless they are 4D, in which case I wouldn't advice to use models pretrained on 3D images anyway.
Comments.UserDisplayName: Edoardo Guerriero
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-03-20T12:28:38.453Z
Comments.Text: just to be extra clear, what are the 91, 109, 91 numbers you mention? Are they 91=height, 109=width, 91=channels? or 91=height, 109=width, 91=extra dimension + 3=channels (RGB)?
Comments.UserDisplayName: Edoardo Guerriero
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-03-20T18:08:35.383Z
Comments.Text: Sorry for late response, 91x109x91 are height, width, depth, in this order. We have 3D models (cubes - MRI scans of the brains)
Comments.UserDisplayName: Amadej Šenk
Tags: <convolutional-neural-networks><classification><image-recognition><probability><3d-convolution>
Title: How to convert prediction probabilities of 2D images (initially 3D image) to 3D image predictions?
UserDisplayName: Amadej Šenk
ThreadText: # How to convert prediction probabilities of 2D images (initially 3D image) to 3D image predictions?
  
  (Asked by: username_0 on 2022-03-19)
  
  Classification: binary
  Model: CNN (ResNet50V2)
  During our research we've had 91x109x91 images (3-dimensional). We've used 2D CNN to train and evaluate our images and make predictions on labelled cases, thus we had to convert 3D to 2D this way (slices (n*x), y, z, #color_channels):
  maindata = maindata.reshape(n * 91, 109, 91, 3)
  
  What we did here effectively is merge a number of images (n) with dimension x (in our case 91). So we basically trained our model on slices (2D images) of this 3D image. Thus far everything was good. We've received great results.
  However, now we need to create prediction probabilities of n images (3D images) and not n x 91 slices (2D images).
  Can we take the prediction probabilities we've received (2D) and for every 91 prediction probabilities calculate the mean or is there a better way of interpreting 2D results to 3D images?
  Both train (labelled) and test (unlabelled) data are shaped the same way, so the only part missing is interpretation to 3D.
  
  **Tags:** convolutional-neural-networks, classification, image-recognition, probability, 3d-convolution
  > **Comments:**
  > **username_1**: two questions: you say you have images of size 91x109x91 but then you say you reshaped them this way (n * 91, 109, 91, 3), introducing channels, so are your images normal 3d images or 4d? Also it's not clear to me why did you have to reshape to 2d? 2d convolutions don't need reshaping, it's called 2d only cause the kernel move along the x and y axis (2d) but the kernel can be 3d, actually that's the standard procedure when processing images.  
  > **username_0**: We were unable to find Conv3D in Tensorflow library (https://www.tensorflow.org/api_docs/python/tf/keras/applications/resnet). Answer to questions: 1. I have an array of 3D images (4 dimensions), I need to rescale the dimensions to 2D for each image in order to use any of the Conv2D they use (Tensorflow).  2. Keras models only support 4 parameters, that is (#images, x, y, #color channels), not the depth dimension(z axis) that we would require.  
  > **username_1**: Sorry but I'm still confused cause saying 3D images with 4 dimensions is a contradiction. You talk about depth, is that the extra 4th dimension you have along with the 3D RGB image? Or is the 4th dimension just the batch size?  
  > **username_1**: Moreover if i look at the documentation of [resnet50](https://www.tensorflow.org/api_docs/python/tf/keras/applications/resnet50/ResNet50) they explicitly write the allowed input dimension, either (224, 224, 3) or (3, 224, 224), which follow the standard resnet paper architecture. So again I don't see why is necessary to reshape your input images. Unless they are 4D, in which case I wouldn't advice to use models pretrained on 3D images anyway.  
  > **username_1**: just to be extra clear, what are the 91, 109, 91 numbers you mention? Are they 91=height, 109=width, 91=channels? or 91=height, 109=width, 91=extra dimension + 3=channels (RGB)?  
  > **username_0**: Sorry for late response, 91x109x91 are height, width, depth, in this order. We have 3D models (cubes - MRI scans of the brains)  
  
  ---
  
  ## 0 answers
  
  