BatchNormalization Bijector 结果错误,带有“prob”方法

发布于 2025-01-17 07:55:25 字数 1612 浏览 0 评论 0 原文

我正在尝试根据RealnVP模型实施归一化流,以进行密度估计。 首先,我试图使它在

当使用批处理两种规范化的两种规范化的两种规范化> 时,该模型会产生预期的结果。但是,当将batchnoralization族列式添加到模型中时,方法 prob log_prob 返回意外结果。

以下是设置该模型的代码段:

layers = 6
dimensions = 2
hidden_units = [512, 512]
bijectors = []

base_dist = tfd.Normal(loc=0.0, scale=1.0)  # specify base distribution

for i in range(layers):
    # Adding the BatchNormalization bijector corrupts the results
    bijectors.append(tfb.BatchNormalization())
    bijectors.append(RealNVP(input_shape=dimensions, n_hidden=hidden_units))
    bijectors.append(tfp.bijectors.Permute([1, 0]))

bijector = tfb.Chain(bijectors=list(reversed(bijectors))[:-1], name='chain_of_real_nvp')

flow = tfd.TransformedDistribution(
    distribution=tfd.Sample(base_dist, sample_shape=[dimensions]),
    bijector=bijector
)

何时批准两种规范化框架,同时进行采样和评估概率回报预期结果:

”构建的热图

,但是,当添加了批次正规化徒时,采样如预期,但评估概率似乎是错误的:

”构建的热图

,因为我对密度估计感兴趣 prob 方法至关重要。完整的代码可以在以下jupyter笔记本中找到:

我知道,在训练和推理过程中,束规范化的两种规范化的行为不同。问题可能是BN徒仍处于训练模式?如果是这样,我该如何将流动转移到推理模式?

I am trying to implement a normalizing flow according to the RealNVP model for density estimation.
First, I am trying to make it work on the "moons" toy dataset.

The model produces the expected result when not using the BatchNormalization bijector. However, when adding the BatchNormalization bijector to the model, the methods prob and log_prob return unexpected results.

Following is a code snippet setting up the model:

layers = 6
dimensions = 2
hidden_units = [512, 512]
bijectors = []

base_dist = tfd.Normal(loc=0.0, scale=1.0)  # specify base distribution

for i in range(layers):
    # Adding the BatchNormalization bijector corrupts the results
    bijectors.append(tfb.BatchNormalization())
    bijectors.append(RealNVP(input_shape=dimensions, n_hidden=hidden_units))
    bijectors.append(tfp.bijectors.Permute([1, 0]))

bijector = tfb.Chain(bijectors=list(reversed(bijectors))[:-1], name='chain_of_real_nvp')

flow = tfd.TransformedDistribution(
    distribution=tfd.Sample(base_dist, sample_shape=[dimensions]),
    bijector=bijector
)

When to BatchNormalization bijector is ommited both sampling and evaluating the probability return expected results:

Without BN: Heatmap constructed with

However, when the BatchNormalization bijector is added, sampling is as expected but evaluating the probability seems wrong:

With BN: Heatmap constructed with

Because I am interested in density estimation the prob method is crucial. The full code can be found in the following jupyter notebook:
https://github.com/mmsbrggr/normalizing-flows/blob/master/moons_training_rnvp.ipynb

I know that the BatchNormalization bijector behaves differently during training and inference. Could the problem be that the BN bijector is still in training mode? If so how can I move the flow to inference mode?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文