I have a hypotethical question: Is it possible to train Conv3D with variable input size?

Sample dim = Length x Width x Depth ; Depth are fixed per each samples, let's say 500. However Length x Width can vary, e.g.:

Sample 1 = 50 x 4 x 500
Sample 2 = 7 x 7 x 500
Sample 3 = 10 x 13 x 500
Sample n = 5 x 32 x 500

These are for classification problems, the next class could have a different sample size, e.g.:

Sample 4 = 6 x 8 x 500 (from class 2)
Sample 5 = 3 x 32 x 500 (from class 2)
Sample m = 10 x 11 x 500 (also from class 2)

Thanks in advance.


1 Answer 1


In Keras, you should specify the shape of your inputs and that shape should be fixed. Then you probably have to somehow resize all of your samples to a fix size $m \times n \times 500$.

You can use similar ideas in image resizing (e.g. interpolation, Nearest-neighbor interpolation, Bilinear and bicubic algorithms, Box Sampling, ...).

  • $\begingroup$ That's the problem. It's not an image but an audio data. Hence image resizing wouldn't make sense here. Is there any possible way to use different input size in Tensorflow? I know in Keras it has to be specified - but how about Tensorflow or PyTorch? $\endgroup$ Commented Dec 11, 2019 at 6:52
  • $\begingroup$ @user2754279 what is the nature of your samples? Is there any way to convert all samples to a unique-shape samples? For example for each samples and each depth, you can embed the average, maximum, minimum and train your model with 3x500 samples. $\endgroup$
    – aminrd
    Commented Dec 11, 2019 at 18:28
  • $\begingroup$ It's high-frequency time-series. So, e.g. pixel x1,y1 contains time-series with a length of 500 data-points. The depth (500 data points) are the same until xm, yn and this is true for all samples. However 'm' and 'n' might be different for each sample. $\endgroup$ Commented Dec 13, 2019 at 8:13
  • $\begingroup$ Another thing is: there is a local connectivity between the neighboring pixels. For instance in area of x10;y10, x11;y11, x10;y13, x12;y10, x9;y12 shares a similar properties. That is the depth value within these pixel clusters are small changing but in gradual way. But if we're looking into far away located pixel, e.g. x50;y85 or x58;y76 then the depth value might be completely far away from the above-mentioned clusters. I am thinking YOLO-v2 or v3 might be able to train this kind of data - but I am not sure. What do you suggest? $\endgroup$ Commented Dec 13, 2019 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.