pon*_*nir 3 python deep-learning keras
基本上,我想编写一个损失函数来计算比较批次的标签和输出的分数。为此,我需要修复批量大小。
我之前在 Tensorflow 中做过,我可以在占位符函数中设置批量大小。现在,我需要在提供给我的 Keras 代码中使用类似的机制。我不知道在这里怎么做。
conv1 = (Conv2D(32, (3,3), padding='same', kernel_regularizer=regularizers.l2(weight_decay), input_shape=x_train.shape[1:], activation='elu'))(input_img)
print(conv1.shape)
Run Code Online (Sandbox Code Playgroud)
打印语句的输出显然是[?, 32, 32, 3]. 我该怎么做,说[64, 32, 32, 3]?
使用keras.layers.Inputlayer 指定批量大小:
from keras.layers import Conv2D, Input
from keras import regularizers
x = Input(shape=(32, 32, 3), batch_size=64)
conv1 = Conv2D(filters=32,
kernel_size=(3,3),
padding='same',
kernel_regularizer=regularizers.l2(1.),
input_shape=(32, 32, 3),
activation='elu')(x)
print(conv1.shape) # (64, 32, 32, 32)
Run Code Online (Sandbox Code Playgroud)