GroupNorm changes the batch size when input resolution changes between calls

Aperta Adatta ai principianti
#323 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, tensorflow

Direzione di ricerca

Inizia da sonnet/src/group_norm.py, in particolare dall’inizializzazione delle shape e dai passaggi di reshape collegati nell’issue, e segui come vengono mantenute le dimensioni spaziali tra una chiamata e l’altra. Aggiungi un test di regressione che usi un’unica istanza di GroupNorm con due risoluzioni di input; verifica che entrambe le uscite corrispondano alle forme dei rispettivi input, poi esegui i test GroupNorm pertinenti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Reusing snt.GroupNorm(groups=2) on a larger image silently changes the batch size from 1 to 4. Only the height and width change between calls. The input rank, channel count, and batch size stay the same, and all optional arguments use their defaults.

Reproduction
import sonnet as snt
import tensorflow as tf

with tf.device("/CPU:0"):
    norm = snt.GroupNorm(groups=2)
    for size in (32, 64):
        x = tf.zeros([1, size, size, 4])
        y = norm(x)
        print(x.shape.as_list(), "->", y.shape.as_list())

    print("Fresh instance:", snt.GroupNorm(groups=2)(x).shape.as_list())
Observed output
[1, 32, 32, 4] -> [1, 32, 32, 4]
[1, 64, 64, 4] -> [4, 32, 32, 4]
Fresh instance: [1, 64, 64, 4]
Expected behavior

The second call should return [1, 64, 64, 4], just as the fresh instance does. GroupNorm.__call__ documents that the output has the same shape as the input. [API contract](https://github.com/google-deepmind/sonnet/blob/1c3b3e4dad22de663e992107531d2966fd7904aa/sonnet/src/group_norm.py#L150-L151)

Why the batch size changes

The first call caches [-1, 32, 32, 2, 2] as the grouped shape and [-1, 32, 32, 4] as the output shape. On the second call, TensorFlow infers 4 for the leading -1. GroupNorm therefore computes the normalization statistics separately for four pieces of the same image before returning them as four batch entries. [Shape initialization](https://github.com/google-deepmind/sonnet/blob/1c3b3e4dad22de663e992107531d2966fd7904aa/sonnet/src/group_norm.py#L220-L230) · [Reshape and normalization](https://github.com/google-deepmind/sonnet/blob/1c3b3e4dad22de663e992107531d2966fd7904aa/sonnet/src/group_norm.py#L172-L182)

Tested environment
dm-sonnet==2.0.2, tensorflow==2.15.1, Python 3.10.20, Windows build 26200, CPU, eager execution.

Lingua principale
Python
Stelle
10k
Fork
1.3k
Merge medio
50m
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di google-deepmind/sonnet

Tutte le issue di google-deepmind/sonnet

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.