XingangPan/DragGAN · error · ValueError
cannot parse 2-vector {s}
Error message
cannot parse 2-vector {s} What it means
Raised by legacy.convert_tf_generator when converting an official TensorFlow StyleGAN/StyleGAN2 generator pickle whose internal version attribute is below 4. Only TF pickles of version >= 4 (StyleGAN2 or later configs) are supported by the PyTorch conversion path; older v1-v3 network classes have incompatible static_kwargs and params layout.
Source
Thrown at gen_images.py:53
if m:
ranges.extend(range(int(m.group(1)), int(m.group(2))+1))
else:
ranges.append(int(p))
return ranges
#----------------------------------------------------------------------------
def parse_vec2(s: Union[str, Tuple[float, float]]) -> Tuple[float, float]:
'''Parse a floating point 2-vector of syntax 'a,b'.
Example:
'0,1' returns (0,1)
'''
if isinstance(s, tuple): return s
parts = s.split(',')
if len(parts) == 2:
return (float(parts[0]), float(parts[1]))
raise ValueError(f'cannot parse 2-vector {s}')
#----------------------------------------------------------------------------
def make_transform(translate: Tuple[float,float], angle: float):
m = np.eye(3)
s = np.sin(angle/360.0*np.pi*2)
c = np.cos(angle/360.0*np.pi*2)
m[0][0] = c
m[0][1] = s
m[0][2] = translate[0]
m[1][0] = -s
m[1][1] = c
m[1][2] = translate[1]
return m
#----------------------------------------------------------------------------
@click.command()View on GitHub (pinned to 336f120ce1)
Solutions
- Use a StyleGAN2/StyleGAN2-ADA TensorFlow pickle with version >= 4 (the official stylegan2-ada-pytorch ones)
- Re-export the TF network from the original stylegan2 repo ensuring version is set
- If you must convert an old StyleGAN v1 network, write a custom converter instead of convert_tf_generator
- Load pre-converted PyTorch .pkl checkpoints directly (already TorchScript/native) so no TF conversion runs
Example fix
# before
G = legacy.load_network_pickle('stylegan1-1024x1024.pkl') # version < 4 -> ValueError
# after
G = legacy.load_network_pickle('stylegan2-ffhq-1024x1024.pkl') # version >= 4 / native Defensive patterns
Strategy: validation
Validate before calling
import pickle
with open(tf_pkl, 'rb') as f: net = pickle.load(f)
if net.version < 4:
raise ValueError('Needs a StyleGAN2-era (version>=4) TF pickle') Type guard
def is_convertible_tf_generator(tf_G) -> bool:
return getattr(tf_G, 'version', 0) >= 4 Try / catch
try:
G = legacy.convert_tf_generator(tf_G)
except ValueError as e:
if 'version too low' in str(e):
# source a v4 pickle or write a custom converter
...
raise Prevention
- Use official stylegan2-ada TF exports (version >= 4)
- Prefer pre-converted PyTorch pickles
- Check the version attribute before attempting conversion
When it happens
Trigger: Calling legacy.load_network_pickle on a TensorFlow .pkl from the original StyleGAN (v1/v2/v3) repo or an early experimental checkpoint instead of a StyleGAN2-era pickle; converting TF networks exported before the version field was standardized to 4.
Common situations: Trying to port weights from the original stylegun/stylegan repo (2019) or stylegan2 TensorFlow pickles with nonstandard versions; pickles re-saved by third-party tools that dropped/renamed the version attribute.
Related errors
- Unknown TensorFlow kwarg
- TensorFlow pickle version too low
- Cannot infer type name from input
- No data received
- Google Drive virus checker nag
AI-assisted analysis of XingangPan/DragGAN@336f120ce1 (2026-08-27).
Data as JSON: /api/errors/bff3054846d66cbd.
Report an issue: GitHub.