Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import keras as ks
- import numpy as np
- features = np.zeros((1,13,22))
- print('features:', features.shape)
- input_size = features.shape[1:] #input_size (13, 22)
- print('input_size:', input_size)
- # input layer
- input_layer = ks.layers.Input(shape=(*input_size,), name='input')
- print('input:', input_layer.shape) # (?, 13, 22)
- # noise
- x = ks.layers.GaussianNoise(stddev=0.1)(input_layer)
- print('1', x.shape) # (?, 13, 22)
- # conv layer
- x = ks.layers.Conv1D(filters=8, kernel_size=3, strides=1, activation=ks.activations.relu, padding='same')(x)
- print('2', x.shape) # (?, 13, 8)
- x = ks.layers.ZeroPadding1D(padding=(1, 0))(x)
- print('3', x.shape) # (?, 14, 8)
- x = ks.layers.MaxPool1D(pool_size=2, strides=None)(x)
- print('4', x.shape) # (?, 7, 8)
- x = ks.layers.Conv1D(filters=8, kernel_size=3, strides=1, activation=ks.activations.relu, padding='same')(x)
- print('5', x.shape) # (?, 7, 8)
- x = ks.layers.UpSampling1D(size=2)(x)
- print('6', x.shape) # (?, 14, 8)
- x = ks.layers.Conv1D(filters=8, kernel_size=3, strides=1, activation=ks.activations.relu, padding='same')(x)
- print('7', x.shape) # (?, 14, 8)
- x = ks.layers.Conv1D(filters=input_size[-1], kernel_size=3, strides=1, activation=ks.activations.relu, padding='same')(x)
- print('8', x.shape) # (?, 14, 22)
- # output
- output_layer = x
- print('output', output_layer.shape)
- model = ks.models.Model(inputs=input_layer, outputs=output_layer)
- model.compile(optimizer='rmsprop',
- loss='categorical_crossentropy',
- metrics=['accuracy'])
- print(model.summary())
- labels = np.zeros((1,13,22)) # gives error
- #labels = np.zeros((1,14,22)) # works correctly
- model.fit(features, labels) # <--- # ValueError: Error when checking target: expected conv1d_4 to have shape (14, 22) but got array with shape (13, 22)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement