fidjax
1.0.0
Implementasi bersih Frechet Inception Distance di JAX.
pathlib
API.1️⃣ FID JAX adalah file tunggal, jadi Anda cukup menyalinnya ke direktori proyek Anda. Atau Anda dapat menginstal paketnya:
pip install fidjax
2️⃣ Unduh bobot Inception (kredit untuk Matthias Wright):
wget https://www.dropbox.com/s/xt6zvlvt22dcwck/inception_v3_weights_fid.pickle ? dl=1
3️⃣ Unduh statistik referensi ImageNet dengan resolusi yang diinginkan (buat sendiri untuk kumpulan data lain):
wget https://openaipublic.blob.core.windows.net/diffusion/jul-2021/ref_batches/imagenet/64/VIRTUAL_imagenet64_labeled.npz
wget https://openaipublic.blob.core.windows.net/diffusion/jul-2021/ref_batches/imagenet/128/VIRTUAL_imagenet128_labeled.npz
wget https://openaipublic.blob.core.windows.net/diffusion/jul-2021/ref_batches/imagenet/256/VIRTUAL_imagenet256_labeled.npz
wget https://openaipublic.blob.core.windows.net/diffusion/jul-2021/ref_batches/imagenet/512/VIRTUAL_imagenet512.npz
4️⃣ Hitung aktivasi, statistik, dan skor di JAX:
import fidjax
import numpy as np
weights = './inception_v3_weights_fid.pickle?dl=1'
reference = './VIRTUAL_imagenet128_labeled.npz'
fid = fidjax . FID ( weights , reference )
fid_total = 50000
fid_batch = 1000
acts = []
for range ( fid_total // fid_batch ):
samples = ... # (B, H, W, 3) jnp.uint8
acts . append ( fid . compute_acts ( samples ))
stats = fid . compute_stats ( acts )
score = fid . compute_score ( stats )
print ( float ( score )) # FID
Kumpulan data | Model | FID JAX | OpenAI TF |
---|---|---|---|
GambarNet 256 | ADM (dipandu, diambil sampelnya) | 3.937 | 3.943 |
Arahkan ke file melalui implementasi pathlib.Path
yang mendukung penyimpanan Cloud Anda. Misalnya untuk GCS:
import elements # pip install elements
import fidjax
weights = elements . Path ( 'gs://bucket/fid/inception_v3_weights_fid.pickle' )
reference = elements . Path ( 'gs://bucket/fid/VIRTUAL_imagenet128_labeled.npz' )
fid = fidjax . FID ( weights , reference )
Hasilkan statistik referensi untuk kumpulan data khusus:
import fidjax
import numpy as np
weights = './inception_v3_weights_fid.pickle?dl=1'
fid = fidjax . FID ( weights )
acts = fid . compute_acts ( images )
mu , sigma = fid . compute_stats ( acts )
np . savez ( 'reference.npz' , { 'mu' : mu , 'sigma' : sigma })
Silakan ajukan masalah di Github.