Code Monkey home page Code Monkey logo

pixyz's People

Contributors

ahahsak avatar ishohei220 avatar kanekotakaaki avatar kenoharada avatar ktaaaki avatar masa-su avatar nnknk0802 avatar rnagumo avatar tmats avatar u-kob avatar ypjp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pixyz's Issues

Add Tars.contrib

Tarsを用いた深層確率モデルの論文実装を置いておきたい.
例:世界モデル系
・DRAW系
・GQN系
・TD-VAE

どれくらいの粒度の実装にするかは要議論(層をカスタマイズできるようにするのか等)

Change the name of evaluation method in each API

各APIで評価のメソッド名がバラバラなので,統一したい.

  • Distribtion API
    • 尤度の評価:p.log_likelihood -> p.loglike.eval
  • Loss API
    • Lossの評価:loss.estimate -> loss.eval
  • Model API
    • Modelの評価:model.test -> model.eval

Annealing beta in the loss function

Hi! Thanks again for the library.

Is it possible to implement KL cost annealing in the loss function of Model object? The full loss function is assigned when the Model object is created, thus not allowing to change the beta term during the training.

Implementation of NVAE

Hi, I just came across this library and it looks awesome. Keep up the good work!

I was just wondering if a model such as the NVAE (https://arxiv.org/abs/2007.03898), i.e. a hierarchical VAE, with an inference and generative network that shares parameters with each other, will be possible to implement using the Pixyz framework.

Thank you in advance!

Your Glow or RealNVP's implementation is forgot Split Layer, I think

こんにちは、TFP から pixyz のコード翻訳を勉強しています。

現在 TFP は flow-base モデルの対数尤度をきちんと計算できていないので、こちらに全体のコードを移したいと考えています。

example の ipynb を読んでいると、Glow, RealNVP の ipynb に Split レイヤーが欠けていることに気が付きました。

本来これらの実装は、https://github.com/MokkeMeguru/glow-realnvp-tutorial/blob/master/examples/jupyter_notebooks/Glow_mnist.ipynb にあるように Split レイヤー(私の実装で言う Blockwise3D)が存在します。

現状 Splitレイヤー の実装はできますか?

Errors in examples/vae

I met two errors while running VAE example in examples.
https://github.com/masa-su/Tars_pytorch/blob/master/examples/vae.ipynb

First, The name of module was renamed in Tars.distributions.

  • NormalModel and BernoulliModel were renamed to Normal and Bernoulli

Second, after fixing the first one, I met the error as below when running the last cell.
I can't find how to fix this for now.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-10-21cc15672efd> in <module>()
      7 
      8 for epoch in range(1, epochs + 1):
----> 9     train_loss = train(epoch)
     10     test_loss = test(epoch)
     11 

<ipython-input-7-d073e7c2f1ba> in train(epoch)
      3     for batch_idx, (data, _) in enumerate(tqdm(train_loader)):
      4         data = data.to(device)
----> 5         lower_bound, loss = model.train({"x": data.view(-1, 784)})
      6         train_loss += loss
      7 

~/workspace/tars/Tars_pytorch/Tars/models/vae.py in train(self, train_x, coef)
     34 
     35         self.optimizer.zero_grad()
---> 36         lower_bound, loss = self._elbo(train_x, coef)
     37 
     38         # backprop

~/workspace/tars/Tars_pytorch/Tars/models/vae.py in _elbo(self, x, reg_coef)
     61 
     62         # reconstrunction error
---> 63         samples = self.encoder.sample(x)
     64         log_like = self.decoder.log_likelihood(samples)
     65 

~/workspace/tars/Tars_pytorch/Tars/distributions/distributions.py in sample(self, x, shape, batch_size, return_all, reparam)
    137         else:  # conditional
    138             x = self._verify_input(x)
--> 139             self._set_distribution(x)
    140 
    141             output = {self.var[0]: self._get_sample(reparam=reparam)}

~/workspace/tars/Tars_pytorch/Tars/distributions/distributions.py in _set_distribution(self, x)
     50 
     51     def _set_distribution(self, x={}):
---> 52         params = self.get_params(**x)
     53         self.dist = self.DistributionTorch(**params)
     54 

~/workspace/tars/Tars_pytorch/Tars/distributions/distributions.py in get_params(self, **params)
    113 
    114         # append constant_params to map_dict
--> 115         output.update(self.constant_params)
    116 
    117         return output

AttributeError: 'tuple' object has no attribute 'update'

Add the "marginalization" option

周辺化の演算を行うメソッドを追加したい.
つまり,p(x,z)を周辺化してp(x)とする感じ.
サンプリングするときに楽(ただし,周辺化すると尤度は計算できなくなる)

print(p)
>> p(x,z)
p = p.marginalize({"z":z})
print(p)
>> p(x)

Name of the library

Libraryの名前について書いていく(ブレスト的にやっていく)
採用は鈴木くんのお気持ち次第?

Implementation of the MVAE model

First of all thank you for the code! Just two slight remark:

  • The implementation of the MVAE model provided considers KL divergence terms between the distributions of each modality-specific encoder and the distribution of the Product-of-Experts (POE) encoder.

dkl

However, the original formulation of the MVAE model (in the paper Multimodal Generative Models for Scalable Weakly-Supervised Learning), does not consider such terms, only a KL divergence term between the distribution of the POE encoder and the prior:

elbo

When I remove the kl_x and kl_y terms from the regularizer and train, the model seems unable to perform cross-modality inference:

cmi

  • The authors of the paper also mention a subsampling training procedure, where the total loss function for a batch is the sum of three different losses: (1) a joint-loss, where image and text are given as input to the model, (2) an image loss, where only image is given as input to the model, (3) a text loss, where only text is given as input to the model. Would that be possible to implement with the Pixyz framework?

Add the Data distribution and the degenerate distribution

データ分布と退化分布を実装する.

  • データ分布

    • 単純に入力と同じ値を返すだけの分布.確率分布の操作時に利用するだけだが,これがあると全て同時分布として扱えるようになる.
  • 退化分布

    • 分布を指定せずにDNNの出力をそのまま出力する分布.尤度は評価できないが,GANのGeneratorとして利用する.

Change the way to handle the prior distribution of hyperparameters

今のところ,ガウス分布のmuとsigmaの事前分布を指定できない.これは$N(x;\mu,\sigma^2)$と考えているため.

ハイパーパラメータの事前分布を定めるには,muとsigmaが確率変数,即ち$N(x|\mu,\sigma^2)$と扱えるようにしなければならない.

Implement GAN models

GAN系の実装
とりあえずは旧Tarsと同様GANクラスを作って実装する感じにする.

Plot graphical models

実装した同時分布をグラフィカルに可視化したい.
現在は,prob_textで因数分解した形をテキストで確認できる.

Daftとか使いたい.
http://daft-pgm.org/

IterativeLoss may have a bug(?)

現在pixyz/DMMを参考にしてSSMを使った映像生成をしています。
(こちらを見ていただきたいです。bair pushing datasetを使っています)
https://github.com/naruya/ssm-pixyz/blob/issue1/SSM
(このコミットのコードで実験を回しました)
https://github.com/naruya/ssm-pixyz/commit/fb044a89c1581bd415def38caf9163cda458d33b

以下の4つのloss関数(は同じ値をとると思うんですが、)をIterativeLossを使って定義したところ、それぞれ異なる値をとっていました。

Screenshot 2019-12-24 at 17 51 55

4つのlossの定義はこちらで
https://github.com/naruya/ssm-pixyz/blob/issue1/SSM/model.py
print_latex結果はこちらにも上げています。
https://github.com/naruya/ssm-pixyz/blob/issue1/SSM/_sample.ipynb

以下のmain.pyを実行して4つのlossの値を比較しました。
https://github.com/naruya/ssm-pixyz/blob/issue1/SSM/main.py

seq_len == 1 のときとseq_len == 3 のときをそれぞれ3回ずつ試しました。
loss1, loss2, loss3, loss4が上の画像に相当するloss関数の値で、
_ce, _klは参考までに出力してみています、具体的な内容はコードを見ていただきたいです。

seq_len == 1 のとき

loss1, loss2, loss3, loss4 を比較すると、loss2だけですが異常な値をとっていました。
loss_ce2, loss_kl2 は loss3, loss4 のときと同じような値をとっているので、自分の書き方が悪かったのかもしれませんが、IterativeLossLossOperator の挙動が期待と違うのかもしれないと思い載せました。

Screenshot 2019-12-24 at 18 19 49

seq_len == 3 のとき

loss1, loss2, loss3, loss4 を比較すると、loss3とloss4だけ一致し、その他はバラバラな値をとっていました。(loss3とloss4の実装はもともとほとんど同じではあります。)
seq_len == 1 の比較しloss1も異なる値をとるようになっているので、IterativeLoss内のupdate周りにバグがある気がしています。

Screenshot 2019-12-24 at 18 31 36

以上報告になります。

Add ELBO and NLL as Loss classes

Lossクラスを継承する形で,ELBOやNLLを実装する.
これによって,
Distributions <-> Losses <-> Models
という関係になる.

ただし,そうするとModelsがもはやModelsではないのではないかという説もある(ので,この辺りご意見いただけると嬉しいです)

Encoder is executed 2 times in VAE

以下のような VAE を実装して実行すると Encoder が2回実行されます。

import torch
import torch.nn as nn
from pixyz.distributions import Normal
from pixyz.losses import KullbackLeibler
from pixyz.models import VAE
import torch.optim as optim

class Encoder(Normal):
    def __init__(self):
        super().__init__(cond_var=["x"], var=["z"], name="q")
        self.linear = nn.Linear(10, 10)

    def forward(self, x):
        print("Encoder")
        return {"loc": self.linear(x), "scale": 1.0}

class Decoder(Normal):
    def __init__(self):
        super().__init__(cond_var=["z"], var=["x"], name="p")

    def forward(self, z):
        print("Decoder")
        return {"loc": z, "scale": 1.0}

def prior():
    return Normal(loc=torch.tensor(0.), scale=torch.tensor(1.), var=["z"], features_shape=[10], name="p_{prior}")

q = Encoder()
p = Decoder()

prior = prior()
kl = KullbackLeibler(q, prior)

mdl = VAE(q, p, regularizer=kl, optimizer=optim.Adam, optimizer_params={"lr":1e-3})

x = torch.zeros((10, 10))
loss = mdl.train({"x": x})

出力

Encoder
Decoder
Encoder

KL divergence と再構成誤差のそれぞれで Encoder を実行しているように見えます。
Encoder を2回実行すると、その分学習時間が長くかかるため、1回で済ませたいのですが、方法はありますでしょうか?

feature request: MultivariateNormal

Will it be possible to support multivariate normal distributions just like pytorch does, where user can provide custom covariance matrix in the future?
I want to implement a VAE where the inference model produce a mean and a first-order autoregressive covariance matrix, and the posterior distribution is multivariate.

Add train_batch and train methods

現在のtrainはbatchごとに受け取って計算する形になっているが,毎回外側でepochのiterationを書くのが面倒.そこで,従来のtrainをtrain_batchと変更し,イテレーターを受け取って1epoch分学習するtrainメソッドを実装する.

for epoch in range(1, epochs + 1):
    train_loss = model.train(train_loader)

testも同じ(pytorchにあわせて,testもevalに変更するかも)

Write an introduction and tutorials in English

英語でREADMEやチュートリアルを書く.
バージョンが上がって書き方などが多少変わっているので,チュートリアルも再構成する必要がある.

Add the Loss class

VAEとか,任意のlossを実装できるようにしたいので,lossクラスを作って,それらで四則演算できるようにするといいかもしれない.
そうすると

  1. 確率モデルの設計
  2. 誤差関数の設計
    を独立にできる.

通常の確率モデルは,1を設計した時点で2も決定するんだけど(尤度最大化など),深層生成モデルではlossをad-hocに設計することが多いので,このほうが嬉しい.

今はKullbackLeiblerなどがdivergenceの一つとして実装されている.これを全てLossクラスを継承する形に修正する.

例えば,こんな感じ

rec = Reconstruction(q, p)
div = KullbackLeibler(prior, q)
loss = rec - div
loss.estimate({"x": x})

typo in README.md

In the "Quick Start" section in README.md

>>> prior = Normal(loc=torch.tensor(0.), scale=torch.tensor(1.),
...                var=["z"], features_dim=[64], name="p_prior")

There is no attribute "features_dim" in the "Normal" class.
Is this a mistake of "features_shape"?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.