0

I am working on a model employing the usage of tf.keras.Conv2D which analyses many planes of patterns over a period of time, with the model input shape being (None, 9, 19, 19), 9 being the number of time frames observed. The reason the input shape is the way it is is that I align 19x19 patterns across time to form an array. When converted into a tf.constant, this array has a shape of (9, 19, 19).

Here's the catch: tf.keras.Conv2D by default sees the last entry of the input shape as the depth and keeps the 2nd and 3rd entries consistent. This means that if I keep the network input shape, the shape taken by the new Conv2D layer would have shape (None, 9, 19, filter_numer) but the 2D dimensionality I wanted was 19x19, not 9x19. If I change my input shape from (9, 19, 19) to (19, 19, 9), the time taken will greatly increase as there would be many evaluations. My program requires the processing time to be as low as possible, reshaping the matrix would take much more time than I would have liked. Any suggestions would be greatly appreciated.

Magister
  • 21
  • 5

1 Answers1

0

I figured it out, Conv2D has an optional parameter called data_format. If data_format == 'channels_first' (default is 'channels_last'), the new Conv2D layer would have the intended shape (None, filter_number, 19, 19).

Unfortunately, TensorFlow 2.2 doesn't support channels_first data format just yet:

tensorflow.python.eager.core._NotOkStatusException: UnimplementedError: {{function_node __inference_keras_scratch_graph_1087}} The Conv2D op currently only supports the NHWC tensor format on the CPU. The op was given the format: NCHW
     [[{{node conv2d/Conv2D}}]] [Op:__inference_keras_scratch_graph_1087]

Convert between NHWC and NCHW in TensorFlow provides an alternative way for conversion.

(I've just realized how shallow my knowledge on this library really is...)

Magister
  • 21
  • 5