TFHub conversion
Use this route only for the repository's legacy TFHub/converter.py workflow:
porting a DeepMind BigGAN generator downloaded from TensorFlow Hub into a
PyTorch .pth state dictionary. The supported resolutions are 128, 256, and
512. This is not a general TensorFlow-to-PyTorch conversion tool and it does
not convert a discriminator or a complete training checkpoint.
Reference-only status. This workflow is reference-only unless an isolated environment with legacy TensorFlow 1.x-compatible APIs, TensorFlow Hub, the required Python packages, network access (or a suitable existing HDF5 intermediate), and a compatible CUDA GPU for sampling is deliberately available. It was not runtime verified. In particular, do not report a successful conversion merely because the Python files parse or because
load_state_dict(..., strict=False)returns.
Read before acting
- Read
references/workflows.mdfor the end-to-end command sequence, working directory requirement, download/cache behavior, outputs, and sample checks. - Read
references/api-reference.mdfor the converter functions, resolution table, TensorFlow-to-PyTorch mappings, and every command-line flag. - Read
references/troubleshooting.mdbefore changing environments or interpreting a failure.
Prerequisites and hard constraints
The converter imports all of the following: PyTorch, torchvision, h5py,
TensorFlow, tensorflow_hub, and parse. The adjacent
TFHub/biggan_v1.py also imports NumPy and SciPy. The repository's normal
PyTorch dependencies therefore are not sufficient by themselves. Keep the
legacy TensorFlow/TFHub dependencies isolated from the normal training
environment.
The source uses TensorFlow 1.x graph/session APIs, including
tf.reset_default_graph(), tf.global_variables_initializer(), and
tf.Session(), plus the TF1-style hub.Module(...) API. TensorFlow 2.x is
not a drop-in replacement. Do not “fix” this route by silently substituting
TF2 or by claiming compatibility through tf.compat.v1 without separately
reviewing the TFHub module and the complete conversion behavior.
The converter has two important layout assumptions:
- Launch it from the
TFHubdirectory, for examplecd /path/to/BigGAN-PyTorch/TFHub. It imports the siblingbiggan_v1.pyand appends..to find the repository-levelBigGAN.py. Running from another directory can produce relative-import or module-path failures. DEVICEis hard-coded tocuda. Conversion itself reads weights and builds a PyTorch generator, but the optional sample path moves the generator and tensors to CUDA. There is no supported CPU sampling fallback in this script.
Operational outline
- Choose one resolution first. The
--resolution/-rflag accepts exactly128,256, or512. Omitting it converts all three in sequence. - Ensure the TFHub URL can be reached, or place the matching intermediate
biggan-<resolution>.h5in the selected weights directory. If the HDF5 exists and--redownloadis absent, the converter reuses it without contacting TFHub. - Run
converter.pyfromTFHub. It loads the module withtensorflow_hub, initializes the TF graph, writes every TF global variable to HDF5, maps the HDF5 variables through the legacybiggan_v1.pymodel andconvert_from_v1, then instantiates the currentBigGAN.Generator. - It saves the converted generator state dictionary as
biggan-<resolution>.pthunder--weights_dir. This is not a complete checkpoint containing optimizer, discriminator, or EMA training objects. - If
--generate_samplesis supplied, it samples random latent vectors and random ImageNet class ids on CUDA and writesbiggan<resolution>_samples.jpgunder--samples_dir. Use--parallelonly when the visible GPUs and the legacynn.parallel.data_parallelpath are appropriate. - Treat output existence as only a file-level check. A meaningful acceptance
check requires loading the intended state dictionary into the matching
current generator and visually or numerically checking generated images;
neither conversion nor
strict=Falseloading proves semantic equivalence.
Truncation limitation
The TFHub README explicitly says that this port is currently set up to run
without truncation. The converter's generate_sample does not call
biggan_v1.truncated_z_sample; it uses torch.randn and does not establish
standing statistics for truncation levels. The missing per-truncation standing
statistics mean that truncation curves or quality claims at non-default
truncation values are not reproduced by this route. Accumulate and validate
standing statistics separately before attempting truncation experiments, and
record that extra procedure with the result.
Scope and non-goals
This route covers only the checked-in TFHub conversion script and its adjacent legacy reference model. It does not modernize the code, download weights on the user's behalf, guarantee TF2 operation, provide a CPU implementation, create standing statistics, or certify image quality. Do not import this sub-skill into an automatic runtime router without preserving its explicit reference-only and not-runtime-verified warnings.
