{"record":{"id":"2f043e5e92d4da64","repo":"WZMIAOMIAO/deep-learning-for-image-processing","slug":"object-has-no-attribute-2f043e","errorCode":null,"errorMessage":"'{}' object has no attribute '{}'","messagePattern":"'(.+?)' object has no attribute '(.+?)'","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"pytorch_object_detection/retinaNet/train_utils/distributed_utils.py","lineNumber":161,"sourceCode":"\nclass MetricLogger(object):\n    def __init__(self, delimiter=\"\\t\"):\n        self.meters = defaultdict(SmoothedValue)\n        self.delimiter = delimiter\n\n    def update(self, **kwargs):\n        for k, v in kwargs.items():\n            if isinstance(v, torch.Tensor):\n                v = v.item()\n            assert isinstance(v, (float, int))\n            self.meters[k].update(v)\n\n    def __getattr__(self, attr):\n        if attr in self.meters:\n            return self.meters[attr]\n        if attr in self.__dict__:\n            return self.__dict__[attr]\n        raise AttributeError(\"'{}' object has no attribute '{}'\".format(\n            type(self).__name__, attr))\n\n    def __str__(self):\n        loss_str = []\n        for name, meter in self.meters.items():\n            loss_str.append(\n                \"{}: {}\".format(name, str(meter))\n            )\n        return self.delimiter.join(loss_str)\n\n    def synchronize_between_processes(self):\n        for meter in self.meters.values():\n            meter.synchronize_between_processes()\n\n    def add_meter(self, name, meter):\n        self.meters[name] = meter\n\n    def log_every(self, iterable, print_freq, header=None):","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/WZMIAOMIAO/deep-learning-for-image-processing/blob/1ec3fe6f374fc9969973a61f819de25658595afa/pytorch_object_detection/retinaNet/train_utils/distributed_utils.py#L143-L179","documentation":"SmoothedValue meter container implements __getattr__ that raises AttributeError when the requested attribute is neither in self.meters nor self.__dict__. Python's default attribute resolution failure surfaces through this custom path, so accessing a misspelled or never-logged metric name raises this error.","triggerScenarios":"Accessing metric.something on a MetricLogger where 'something' was never registered via meters, e.g. a typo like metric.losss or reading a metric before it was added with meters[key] = SmoothedValue().","commonSituations":"Typos in metric names during train loop logging; expecting a metric that only exists in another repo version; accessing attributes before first training step populated them.","solutions":["Print type(self).meters keys to see registered metric names and fix the typo","Ensure the metric was added before access: metric_logger.meters['name'] = SmoothedValue()","Use getattr(metric, name, default) when metric presence is optional"],"exampleFix":"// before\nprint(metric_logger.lerning_rate)  # typo\n// after\nprint(metric_logger.learning_rate)","handlingStrategy":"try-catch","validationCode":"available = list(metric_logger.meters.keys())\nassert metric_name in available, f'{metric_name} not logged; have {available}'","typeGuard":"def has_metric(logger, name: str) -> bool:\n    return name in getattr(logger, 'meters', {}) or name in getattr(logger, '__dict__', {})","tryCatchPattern":"try:\n    value = getattr(metric_logger, metric_name)\nexcept AttributeError as e:\n    value = None\n    print(f'Metric missing: {e}')","preventionTips":["Check meters keys when adding a new metric read","Avoid hand-typing metric names; reference constants","Log available metrics once at startup for debugging"],"tags":["attributeerror","logging","pytorch","typo"],"backgroundTag":"attribute-not-found","analyzedSha":"1ec3fe6f374fc9969973a61f819de25658595afa","analyzedAt":"2026-08-30T09:19:11.901Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}