Skip to content

Fix _blob_loss_weights cache key typo in pycaffe#7098

Open
Chessing234 wants to merge 1 commit intoBVLC:masterfrom
Chessing234:fix/pycaffe-blob-loss-weights-cache-typo
Open

Fix _blob_loss_weights cache key typo in pycaffe#7098
Chessing234 wants to merge 1 commit intoBVLC:masterfrom
Chessing234:fix/pycaffe-blob-loss-weights-cache-typo

Conversation

@Chessing234
Copy link
Copy Markdown

Bug

Net.blob_loss_weights (set up in python/caffe/pycaffe.py) is a lazily-built, cached OrderedDict mapping blob name to loss weight. The sibling properties in the same file (_Net_blobs, _Net_layer_dict, _Net_params) all follow the pattern:

```python
if not hasattr(self, '_dict'):
self._dict = ...
return self._dict
```

_Net_blob_loss_weights breaks this pattern by a one-character typo:

```python
if not hasattr(self, '_blobs_loss_weights_dict'): # <-- extra 's' after 'blob'
self._blob_loss_weights_dict = OrderedDict(...)
return self._blob_loss_weights_dict
```

Root cause

The hasattr check looks for _blobs_loss_weights_dict, but the assignment and the return use _blob_loss_weights_dict. The two names never match, so the cached attribute is never found and the OrderedDict is rebuilt on every access of net.blob_loss_weights.

Fix

Drop the stray s so the check matches the attribute that actually gets set, matching _Net_blobs a few lines above:

```python
if not hasattr(self, '_blob_loss_weights_dict'):
```

One-character change.

The _Net_blob_loss_weights property intends to lazily build and cache
an OrderedDict on the Net instance, following the same pattern as the
sibling _Net_blobs property (which caches under '_blobs_dict').

The hasattr check, however, looks for '_blobs_loss_weights_dict' (with
an extra 's' after 'blob'), while the assignment and the subsequent
return both use '_blob_loss_weights_dict'. As a result the hasattr
check never finds the cached attribute and the OrderedDict is rebuilt
on every access of net.blob_loss_weights.

Align the hasattr check with the attribute that actually gets set so
the cache is populated after the first call, matching _Net_blobs and
_Net_layer_dict above/below.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant