我目前正在 tensorflow 中构建一个 CNN,我正在使用 He 正常权重初始化来初始化我的权重矩阵。但是,我不确定应该如何初始化我的偏差值。我使用 ReLU 作为每个卷积层之间的激活函数。是否有初始化偏差值的标准方法?
# Define approximate xavier weight initialization (with RelU correction described by He)
def xavier_over_two(shape):
std = np.sqrt(shape[0] * shape[1] * shape[2])
return tf.random_normal(shape, stddev=std)
def bias_init(shape):
return #???
Run Code Online (Sandbox Code Playgroud) Keras中有没有办法指定不需要传递目标数据的损失函数?
我尝试指定一个y_true省略参数的损失函数,如下所示:
def custom_loss(y_pred):
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
Traceback (most recent call last):
File "siamese.py", line 234, in <module>
model.compile(loss=custom_loss,optimizer=Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0))
File "/usr/local/lib/python2.7/dist-packages/keras/engine/training.py", line 911, in compile
sample_weight, mask)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/training.py", line 436, in weighted
score_array = fn(y_true, y_pred)
TypeError: custom_loss() takes exactly 1 argument (2 given)
Run Code Online (Sandbox Code Playgroud)
然后我尝试fit()在不指定任何目标数据的情况下调用:
model.fit(x=[x_train,x_train_warped, affines], batch_size = bs, epochs=1)
Run Code Online (Sandbox Code Playgroud)
但看起来不传递任何目标数据会导致错误:
Traceback (most recent call last):
File "siamese.py", line 264, in <module>
model.fit(x=[x_train,x_train_warped, affines], batch_size = bs, epochs=1)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/training.py", line 1435, …Run Code Online (Sandbox Code Playgroud) 张量流中是否有现有的总和池实现?在搜索文档时,似乎只支持平均和最大池操作。
我有一个 NHWC 张量,其中每个 HxW 矩阵都是一个概率图,我想通过 2x2 总和池对其进行下采样。如果张量流中不存在求和池函数,是否有其他方法可以使用 Python API 实现此下采样操作?