{"record":{"id":"232f8dd5e6c1f5c9","repo":"open-mmlab/mmdetection","slug":"currently-does-not-support-saving-datasample-when","errorCode":null,"errorMessage":"Currently does not support saving datasample when return_datasamples is set to True. Prediction results are not saved!","messagePattern":"Currently does not support saving datasample when return_datasamples is set to True\\. Prediction results are not saved!","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"mmdet/apis/det_inferencer.py","lineNumber":561,"sourceCode":"            - ``visualization`` (Any): Returned by :meth:`visualize`.\n            - ``predictions`` (dict or DataSample): Returned by\n                :meth:`forward` and processed in :meth:`postprocess`.\n                If ``return_datasamples=False``, it usually should be a\n                json-serializable dict containing only basic data elements such\n                as strings and numbers.\n        \"\"\"\n        if no_save_pred is True:\n            pred_out_dir = ''\n\n        result_dict = {}\n        results = preds\n        if not return_datasamples:\n            results = []\n            for pred in preds:\n                result = self.pred2dict(pred, pred_out_dir)\n                results.append(result)\n        elif pred_out_dir != '':\n            warnings.warn('Currently does not support saving datasample '\n                          'when return_datasamples is set to True. '\n                          'Prediction results are not saved!')\n        # Add img to the results after printing and dumping\n        result_dict['predictions'] = results\n        if print_result:\n            print(result_dict)\n        result_dict['visualization'] = visualization\n        return result_dict\n\n    # TODO: The data format and fields saved in json need further discussion.\n    #  Maybe should include model name, timestamp, filename, image info etc.\n    def pred2dict(self,\n                  data_sample: DetDataSample,\n                  pred_out_dir: str = '') -> Dict:\n        \"\"\"Extract elements necessary to represent a prediction into a\n        dictionary.\n\n        It's better to contain only basic data elements such as strings and","sourceCodeStart":543,"sourceCodeEnd":579,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/apis/det_inferencer.py#L543-L579","documentation":"Warning from DetInferencer.postprocess: when return_datasamples=True and pred_out_dir is set, raw datasamples cannot be serialized to disk, so nothing is saved — only the in-memory return value is available.","triggerScenarios":"Calling inferencer(..., return_datasamples=True, out_dir='results/') (pred_out_dir non-empty).","commonSituations":"Users wanting both structured dump files and full DetDataSamples; the JSON dump path only supports pred2dict output, not datasamples.","solutions":["Call twice or choose one: use return_datasamples=True with out_dir='' and serialize datasamples yourself","Or use return_datasamples=False with out_dir to get the standard json/pickle predictions","Convert datasamples to dict via pred2dict before saving"],"exampleFix":"// before\nres = inferencer(imgs, return_datasamples=True, out_dir='out/')  # nothing saved\n// after\nsamples = inferencer(imgs, return_datasamples=True)\n# manually pickle 'samples' if persistence is needed","handlingStrategy":"validation","validationCode":"if return_datasamples and out_dir:\n    print('datasamples will NOT be saved; save them manually')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Don't combine return_datasamples=True with out_dir expecting files","Serialize returned datasamples yourself (pickle)"],"tags":["python","warning","inferencer","serialization","datasamples"],"backgroundTag":"unsupported-output-combination","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}