Yaohong

为了真相不惜被羞辱

How Keras add two layers?

How Keras add two layers?

tf.keras.layers.add() method can add two layer?

What it do is sum the values of corresponding positions in two layers.

For example:


input_shape = (1,2,3)
import tensorflow as tf
tf.enable_eager_execution()

print("----------x1 tensor-----------")
x1 = tf.random.uniform(input_shape, maxval=10, dtype=tf.dtypes.int32)
tf.print(x1);
print("----------x2 tensor-----------")
x2 = tf.random.uniform(input_shape, maxval=10, dtype=tf.dtypes.int32)
tf.print(x2);
print("----------add 2 tensors-----------")
y = tf.keras.layers.add([x1,x2])
tf.print(y);

Output: ———-x1 tensor———– [[[7 6 1] [5 7 2]]] ———-x2 tensor———– [[[0 7 8] [2 9 6]]] ———-add 2 tensors———– [[[7 13 9] [7 16 8]]]


如何计算一个BatchNormalization的参数?

Batch参数=前一层卷积数量x4

如何计算一个BatchNormalization的参数?

# Environment:
# OS			macOS Catalina 10.15.6
# python 		3.7
# pip 			20.1.1
# tensorflow	1.14.0
# Keras 		2.1.5

from keras.models import Sequential
from keras.layers import Conv2D,BatchNormalization
model = Sequential();
# conv2d + max pooling
model.add(
	Conv2D(96, 
		kernel_size = (11,11), 
		strides=(4, 4), 
		padding="valid", 
		input_shape=(224,224,3),
		activation="relu")
	); # output  55 * 55 * 96 

# batchNormalization ! 
model.add(BatchNormalization()) # output
model.summary();

output: