KeyError: 'pytorch-lightning_version'

ANS_CENTER: <pre><code class="lang-auto">Traceback (most recent call last):
File "C:\Users\abdul\smartparking\Project_smartparking\m.py", line 4, in
number_plate_detection_and_reading = pipeline("number_plate_detection_and_reading",
File "C:\Users\abdul\smartparking\Project_smartparking\nomeroff_net\pipelines_init_.py", line 115, in pipeline
return pipeline_class(task, image_loader, **pipeline_kwargs, **kwargs)
File "C:\Users\abdul\smartparking\Project_smartparking\nomeroff_net\pipelines\number_plate_detection_and_reading.py", line 52, in init
self.number_plate_text_reading = NumberPlateTextReading(
File "C:\Users\abdul\smartparking\Project_smartparking\nomeroff_net\pipelines\number_plate_text_reading.py", line 70, in init
self.detector = class_detector(presets, default_label, default_lines_count)
File "C:\Users\abdul\smartparking\Project_smartparking\nomeroff_net\pipes\number_plate_text_readers\text_detector.py", line 45, in init
self.load()
File "C:\Users\abdul\smartparking\Project_smartparking\nomeroff_net\pipes\number_plate_text_readers\text_detector.py", line 60, in load
detector.load(self.presets[detector_name]['model_path'])
File "C:\Users\abdul\smartparking\Project_smartparking\nomeroff_net\pipes\number_plate_text_readers\base\ocr.py", line 314, in load
return self.load_model(path_to_model, nn_class=nn_class)
File "C:\Users\abdul\smartparking\Project_smartparking\nomeroff_net\pipes\number_plate_text_readers\base\ocr.py", line 284, in load_model
self.model = nn_class.load_from_checkpoint(path_to_model,
File "C:\Users\abdul\smartparking\Project_smartparking\project_yolo_craft_resnet\lib\site-packages\pytorch_lightning\core\saving.py", line 139, in load_from_checkpoint
return _load_from_checkpoint(
File "C:\Users\abdul\smartparking\Project_smartparking\project_yolo_craft_resnet\lib\site-packages\pytorch_lightning\core\saving.py", line 163, in _load_from_checkpoint
checkpoint = _pl_migrate_checkpoint(
File "C:\Users\abdul\smartparking\Project_smartparking\project_yolo_craft_resnet\lib\site-packages\pytorch_lightning\utilities\migration\utils.py", line 113, in _pl_migrate_checkpoint
old_version = _get_version(checkpoint)
File "C:\Users\abdul\smartparking\Project_smartparking\project_yolo_craft_resnet\lib\site-packages\pytorch_lightning\utilities\migration\utils.py", line 136, in _get_version
return checkpoint["pytorch-lightning_version"]
KeyError: 'pytorch-lightning_version'
</code></pre>

ptrblck: <p>Your Lightning version seems to expect a <code>'pytorch-lightning_version'</code> key in the <code>state_dict</code> whcih is missing. I don’t know if this is caused by a version mismatch between the lightning release which was used to create the checkpoints vs. the one used to load it, but maybe adding this <code>key</code> to your <code>state_dict</code> with a fake version (e.g. <code>0.0.0</code>) might fix it.</p>

thanhtvt: <p>Sorry for bringing this up, but how can I do that exactly?</p>
<p>I try the following:</p>
<pre><code class="lang-auto">new_ckpt = torch.load(f"{rootdir}/model_state.ckpt")
new_ckpt["pytorch-lightning_version"] = "1.9.0"
torch.save(new_ckpt, f"{rootdir}/fixed_model_state.ckpt")
</code></pre>
<p>It returns error and says <code>RunTimeError: File path/to/fixed_model_state.ckpt cannot be opened</code></p>

ptrblck: <p>Check if you have the needed write access to the used checkpoint folder.</p>