【问题标题】:Manual initialization of conv1d in TensorFlow在 TensorFlow 中手动初始化 conv1d
【发布时间】:2019-04-17 23:36:57
【问题描述】:

如何将自定义系数设置为tf.layers.conv1d。 我发现了如何读取当前系数,但我该如何编写它们呢?

import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt

sess = tf.Session()
order = 5
x = np.zeros(30)
x[10] = 1
y = tf.layers.conv1d(inputs=tf.reshape(x,[1, len(x), 1]),
                     filters=1,
                     kernel_size=order,
                     padding='same')
sess.run(tf.global_variables_initializer())
y_out = sess.run(y)

# get coef
coef = sess.run(tf.all_variables()[-2].value())
print(coef.reshape(order))

以下是 google colab 上带有代码的笔记本的链接: https://colab.research.google.com/drive/1YNSzKmtC88b__LqYcfD-tFHFG3jOZIAz

总的来说,我对如何在 TensorFlow 中制作 FIR 滤波器很感兴趣。

【问题讨论】:

    标签: python tensorflow filter convolution


    【解决方案1】:

    我明白了! 有kerner_initializer参数。

    这就是解决方案

    init_coef = np.array([1,2,3,4,5])[::-1]
    init_coef = tf.initializers.constant(init_coef)
    y = tf.layers.conv1d(inputs=tf.reshape(x,[1, len(x), 1]),
                         filters=1,
                         kernel_size=order,
                         padding='same',
                         kernel_initializer=init_coef)
    

    【讨论】:

      猜你喜欢
      • 2022-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-16
      • 2016-02-16
      • 2017-09-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多