Is my Keras Convolutional Model returning any values?

Viewed 122

For my project I'm mostly following this simple GAN tutorial except that my data is in a time series of 3 values between {-1,1}. I striped away a lot of its complexity to try to understand where the discrepancy is coming from. However, after lots of trail & error and Stack Overflow searches it's time I raise my hand and ask for help. I'm running Python 3.6 / Conda 4.8.3 in a VSCode Jupyter notebook on OSX with TensorFlow 2.0.0. My simplified discriminator does not return any errors in my notebook.

def build_discriminator():

    discriminator_input = Input(shape=(4000,3), name='discriminator_input')
    
    x = discriminator_input

    x = Conv1D(32, 3, strides=1, padding="same", input_shape=(4000,3)) (x)
    
    x = LeakyReLU()(x)

    x = Dropout(0.3)(x)

    x = Flatten()(x)

    discriminator_output = Dense(1, activation='sigmoid')(x)

    return Model(discriminator_input, discriminator_output)


#Test it with some random noise of the same shape as the training data

d = build_discriminator()

noise = tf.random.uniform(
    (1,4000,3), minval=-1, maxval=1, dtype=tf.dtypes.float32
)

decision = d(noise)

Output I'm getting:

print(decision)

<tf.Tensor 'model_1/dense_6/Sigmoid:0' shape=(1, 1) dtype=float32>

I was expecting to put random noise in the untrained discriminator the same size as a training sample and at least get a value between [0,1] to test that the network is processing data.

Expected output:

<tf.Tensor [[0.014325]] shape=(1, 1) dtype=float32>

I need a bit of help interpreting this discrepancy. Does that mean my model isn't processing at all? Or am I missing something more subtle? What do I need to change so that my discriminator returns a tensor of values?

1 Answers

Against recommendations I spend some time removing Keras & Tensorflow from Conda and installing it with pip so that tf.__version__ correctly returned 2.2.0 in the notebook. To my surprise it worked and returned the expected result.

<tf.Tensor: shape=(1, 1), dtype=float32, numpy=array([[0.49497133]], dtype=float32)>

Posting here in case anyone else stumbles across this question with the same problem.

Related