Input 0 of layer "model" is incompatible with the layer: expected shape=(None, n, n, n)

Solution 1:

Running your code with tf.expand_dims does not seem to have any issues, so the error must be somewhere else:

import tensorflow as tf

def state():  
    return tf.expand_dims(tf.keras.utils.normalize(tf.random.normal((250, 319, 3))), axis=0)

def get_actor():
    # Initialize weights between -3e-3 and 3-e3
    last_init = tf.random_uniform_initializer(minval=-0.003, maxval=0.003)

    # Convolutions
    inputs = tf.keras.layers.Input(shape=(250, 319, 3))
    layer1 = tf.keras.layers.Conv2D(32, 3, strides=2, activation="relu")(inputs)
    layer2 = tf.keras.layers.Conv2D(64, 3, strides=4, activation="relu")(layer1)

    layer3 = tf.keras.layers.Flatten()(layer2)

    # Fully connected layers
    layer4 = tf.keras.layers.Dense(256, activation="relu")(layer3)
    layer5 = tf.keras.layers.Dense(256, activation="relu")(layer4)
    action = tf.keras.layers.Dense(3, activation="tanh", kernel_initializer=last_init)(layer5)

    outputs = action
    model = tf.keras.Model(inputs, outputs)
    return model

actor_model = get_actor()
sampled_actions = tf.squeeze(actor_model(state()))
print(sampled_actions)
tf.Tensor([ 0.00166097  0.00444322 -0.00574574], shape=(3,), dtype=float32)