masa-su / pixyz Goto Github PK
View Code? Open in Web Editor NEWA library for developing deep generative models in a more concise, intuitive and extendable way
Home Page: https://pixyz.io
License: MIT License
A library for developing deep generative models in a more concise, intuitive and extendable way
Home Page: https://pixyz.io
License: MIT License
Thank you for your code.
I have a small question: what is 'double_after_norm' used for ?
学習後にサンプルや尤度計算をするときに,torch.no_grad()を書くのが面倒なので,sample
や log_likelihood
の引数で指定できるようにすればいいのではないかという案.
"cond_var" と "var"はやっぱり微妙.
引数の名前を変えたいが,いい案を募集中.
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!
Tarsを用いた深層確率モデルの論文実装を置いておきたい.
例:世界モデル系
・DRAW系
・GQN系
・TD-VAE
どれくらいの粒度の実装にするかは要議論(層をカスタマイズできるようにするのか等)
各クラス・メソッドのテストを書く.
データ分布と退化分布を実装する.
データ分布
退化分布
I would like to use von Mises-Fisher distribution in SVAE.
The paper is Hyperspherical Variational Auto-Encoders and the implementation by authors is here
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.
周辺化の演算を行うメソッドを追加したい.
つまり,p(x,z)を周辺化してp(x)とする感じ.
サンプリングするときに楽(ただし,周辺化すると尤度は計算できなくなる)
print(p)
>> p(x,z)
p = p.marginalize({"z":z})
print(p)
>> p(x)
英語でREADMEやチュートリアルを書く.
バージョンが上がって書き方などが多少変わっているので,チュートリアルも再構成する必要がある.
各APIで評価のメソッド名がバラバラなので,統一したい.
Pytorchの実装を参考にしてTarsに移植したい.
https://github.com/wohlert/generative-query-network-pytorch
Thanks for this code. For reference purposes, can you please mention and add a link to your corresponding Arxiv paper to the readme? I assume it is https://arxiv.org/abs/1611.01891
Lossクラスを継承する形で,ELBOやNLLを実装する.
これによって,
Distributions <-> Losses <-> Models
という関係になる.
ただし,そうするとModelsがもはやModelsではないのではないかという説もある(ので,この辺りご意見いただけると嬉しいです)
real NVPの尤度の評価値がおかしいので修正する必要がある.
実装した同時分布をグラフィカルに可視化したい.
現在は,prob_textで因数分解した形をテキストで確認できる.
Daftとか使いたい.
http://daft-pgm.org/
現在のLossクラスには,出力バッチの和や平均をとる機能がないので,meanとsumメソッドを追加する.
First of all thank you for the code! Just two slight remark:
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:
When I remove the kl_x and kl_y terms from the regularizer and train, the model seems unable to perform cross-modality inference:
GAN系の実装
とりあえずは旧Tarsと同様GANクラスを作って実装する感じにする.
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'
VAEとか,任意のlossを実装できるようにしたいので,lossクラスを作って,それらで四則演算できるようにするといいかもしれない.
そうすると
通常の確率モデルは,1を設計した時点で2も決定するんだけど(尤度最大化など),深層生成モデルではlossをad-hocに設計することが多いので,このほうが嬉しい.
今はKullbackLeiblerなどがdivergenceの一つとして実装されている.これを全てLossクラスを継承する形に修正する.
例えば,こんな感じ
rec = Reconstruction(q, p)
div = KullbackLeibler(prior, q)
loss = rec - div
loss.estimate({"x": x})
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"?
以下のような 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回で済ませたいのですが、方法はありますでしょうか?
今のところ,ガウス分布のmuとsigmaの事前分布を指定できない.これは$N(x;\mu,\sigma^2)$と考えているため.
ハイパーパラメータの事前分布を定めるには,muとsigmaが確率変数,即ち$N(x|\mu,\sigma^2)$と扱えるようにしなければならない.
現在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
を使って定義したところ、それぞれ異なる値をとっていました。
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 のときと同じような値をとっているので、自分の書き方が悪かったのかもしれませんが、IterativeLoss
や LossOperator
の挙動が期待と違うのかもしれないと思い載せました。
seq_len == 3
のときloss1, loss2, loss3, loss4 を比較すると、loss3とloss4だけ一致し、その他はバラバラな値をとっていました。(loss3とloss4の実装はもともとほとんど同じではあります。)
seq_len == 1
の比較しloss1も異なる値をとるようになっているので、IterativeLoss
内のupdate
周りにバグがある気がしています。
以上報告になります。
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.
Libraryの名前について書いていく(ブレスト的にやっていく)
採用は鈴木くんのお気持ち次第?
現在の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に変更するかも)
VAE の学習中に KL divergence や再構成誤差などの損失の一部をそれぞれ独立に確認するにはどのようにすればよいのでしょうか?
こんにちは、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レイヤー の実装はできますか?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.