Fix _blob_loss_weights cache key typo in pycaffe#7098
Open
Chessing234 wants to merge 1 commit intoBVLC:masterfrom
Open
Fix _blob_loss_weights cache key typo in pycaffe#7098Chessing234 wants to merge 1 commit intoBVLC:masterfrom
Chessing234 wants to merge 1 commit intoBVLC:masterfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Net.blob_loss_weights(set up inpython/caffe/pycaffe.py) is a lazily-built, cachedOrderedDictmapping 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_weightsbreaks 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
hasattrcheck 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 theOrderedDictis rebuilt on every access ofnet.blob_loss_weights.Fix
Drop the stray
sso the check matches the attribute that actually gets set, matching_Net_blobsa few lines above:```python
if not hasattr(self, '_blob_loss_weights_dict'):
```
One-character change.