正如在一个类似措辞的问题中提到的(为什么在 c++14 中使用 bind over lambdas?)答案是 - 没有理由(并且还提到为什么使用 lambdas 会更好)。
我的问题是 - 如果在 C++14 中不再有理由使用绑定,为什么标准委员会认为有必要std::bind_front在 C++20 中添加?
它现在比 lambda 有什么新优势吗?
我希望我的部分数据增强将高斯模糊应用于我的训练数据。
为此,我创建了一个自定义 Initializer 类,该类初始化 DepthwiseConv2d 以获得所需的高斯内核。
但我收到以下错误:
tensorflow.python.framework.errors_impl.FailedPreconditionError: {{function_node __inference_Dataset_map_<lambda>_67}} Error while reading resource variable _AnonymousVar0 from Container: localhost. This could mean that the variable was uninitialized. Not found: Resource localhost/_AnonymousVar0/class tensorflow::Var does not exist.
[[{{node depthwise_conv2d/depthwise/ReadVariableOp}}]]
[[IteratorGetNext]] [Op:__inference_distributed_function_694]
Run Code Online (Sandbox Code Playgroud)
这是一个简单的工作示例:
import tensorflow as tf
class GaussianInitializer(tf.keras.initializers.Initializer):
def __init__(self):
super().__init__()
self.sigma = 2
def _gaussian_kernel(self, kernel_size, dtype):
x = tf.range(-kernel_size // 2 + 1, kernel_size // 2 + 1, dtype=dtype)
g = tf.math.exp(-(tf.pow(x, 2) / (2 * tf.pow(tf.cast(self.sigma, dtype), 2))))
g_norm2d …Run Code Online (Sandbox Code Playgroud)