Fix blob_loss_weights cache attribute name typo (cache never hits)#7104
Open
Chessing234 wants to merge 1 commit intoBVLC:masterfrom
Open
Fix blob_loss_weights cache attribute name typo (cache never hits)#7104Chessing234 wants to merge 1 commit intoBVLC:masterfrom
Chessing234 wants to merge 1 commit intoBVLC:masterfrom
Conversation
_Net_blob_loss_weights guards its memoization with hasattr(self, '_blobs_loss_weights_dict') but writes/reads self._blob_loss_weights_dict (no 's' after 'blob'). The guard therefore always evaluates to False and a fresh OrderedDict is built on every access, defeating the cache and making the returned dict a different object on each call. Mutations to the returned dict are also lost on the next access. Align the hasattr name with the attribute that is actually set/returned, matching the pattern of the sibling _Net_blobs / _Net_layer_dict / _Net_params properties.
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_weightsinpython/caffe/pycaffe.pyis intended to memoize theOrderedDictof per-blob loss weights onself, but the guard and the set/return reference two different attribute names:https://github.com/BVLC/caffe/blob/9b89154/python/caffe/pycaffe.py#L35-L44
The guard is
_blobs_loss_weights_dict(plural "blobs"), while the store/return is_blob_loss_weights_dict(singular "blob"). Sohasattralways returns False, a freshOrderedDictis rebuilt on every access, andnet.blob_loss_weights is net.blob_loss_weightsis False. Any mutation of the returned dict is silently lost on the next access.Root cause
Typo in the cache-check attribute name; the sibling properties (
_Net_blobs,_Net_layer_dict,_Net_params,_Net_inputs,_Net_outputs) all use the same name for the guard and the stored attribute.Fix
Change the
hasattrcheck to_blob_loss_weights_dictso the memoization actually hits andnet.blob_loss_weightsreturns the sameOrderedDicton subsequent calls, matching the pattern of the neighbouring properties.