-
Notifications
You must be signed in to change notification settings - Fork 485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AssertError: Checkpoint /home/ec2-user/.torch/iopath_cache/s/dgy9c10wykk4lq4/model_final.pth not found! #168
Comments
Additional info: The bug does not occur on my Mac laptop. It seems to be a Linux problem |
I have the same problem! |
Same here |
So i didn´t solve the problem with the file name, but I find a way to work around it. If you download the model_final.pth mannually it creates a file with the correct filename. So, you can download the model_final.pth and the config.yaml file mannually and call it directly in your scrip by: |
The problem is that this project uses dropbox links layout-parser/src/layoutparser/models/detectron2/catalog.py Lines 19 to 24 in f230971
To address this, this project needs to either:
|
I managed to fix this by tweaking the detectron2 lib. I renamed the DetectionCheckpointer's load method to something else It is defined in ./detectron2/checkpoints/detection_checkpoint.py at line 33: and called in ./detectron2/engine/defaults.py at line 293: I was checking for module name collisions but I'm not sure if that's what fixed it. |
If you actually look at the directory where it complains about (in this case it's |
Update: I have submitted a PR to iopath. While it's being reviewed, you can install
|
Does anyone know how to resolve this issue in Google Colab? |
@nikhilweee pip command above works for now.. |
quickfix- just change the model 'lp://PubLayNet/faster_rcnn_R_50_FPN_3x/config' to something else example 'lp://PubLayNet/mask_rcnn_X_101_32x8d_FPN_3x/config' and run the code; then change back it will redownload the model again |
I tried this, but this just downloaded another
|
Downgrading to detectron2 v0.5 (along with Pillow==9.5.0 to fix another issue, thanks to @gsanch170 for his fix) fixed this problem for me. |
Were you able to fix this? |
Same issue |
As @ppwwyyxx state - the problem is in the file fetching from Dropbox. If you are working on local machine (no future auto deployments using ci/dc or so) - simply rename the files created under: If you into building an auto-deployment module, I suggest to write a function that parse the In the following example, I override the folder to be def load_model(
config_path: str = 'lp://<dataset_name>/<model_name>/config',
):
config_path_split = config_path.split('/')
dataset_name = config_path_split[-3]
model_name = config_path_split[-2]
# get the URLs from the MODEL_CATALOG and the CONFIG_CATALOG
model_url = Detectron2LayoutModel.MODEL_CATALOG[dataset_name][model_name]
config_url = detectron2.catalog.CONFIG_CATALOG[dataset_name][model_name]
# override folder destination:
if 'model' not in os.listdir():
os.mkdir('model')
config_file_path, model_file_path = None, None
for url in [model_url, config_url]:
filename = url.split('/')[-1].split('?')[0]
save_to_path = f"model/" + filename
if 'config' in filename:
config_file_path = copy.deepcopy(save_to_path)
if 'model_final' in filename:
model_file_path = copy.deepcopy(save_to_path)
# skip if file exist in path
if filename in os.listdir("model"):
continue
# Download file from URL
r = requests.get(url, stream=True, headers={'user-agent': 'Wget/1.16 (linux-gnu)'})
with open(save_to_path, "wb") as f:
for chunk in r.iter_content(chunk_size=4096):
if chunk:
f.write(chunk)
return Detectron2LayoutModel(
config_path=config_file_path,
model_path=model_file_path,
) |
AttributeError: module 'detectron2' has no attribute 'catalog' |
I slightly adapted the load_model() function of @m1cha3lya1r in accessing the catalog globals. import layoutparser as lp
from layoutparser.models.detectron2 import catalog
import copy
import os
import requests as requests
def load_model(
config_path: str = 'lp://<dataset_name>/<model_name>/config',
):
config_path_split = config_path.split('/')
dataset_name = config_path_split[-3]
model_name = config_path_split[-2]
# get the URLs from the MODEL_CATALOG and the CONFIG_CATALOG
# (global variables .../layoutparser/models/detectron2/catalog.py)
model_url = catalog.MODEL_CATALOG[dataset_name][model_name]
config_url = catalog.CONFIG_CATALOG[dataset_name][model_name]
# override folder destination:
if 'model' not in os.listdir():
os.mkdir('model')
config_file_path, model_file_path = None, None
for url in [model_url, config_url]:
filename = url.split('/')[-1].split('?')[0]
save_to_path = f"model/" + filename
if 'config' in filename:
config_file_path = copy.deepcopy(save_to_path)
if 'model_final' in filename:
model_file_path = copy.deepcopy(save_to_path)
# skip if file exist in path
if filename in os.listdir("model"):
continue
# Download file from URL
r = requests.get(url, stream=True, headers={'user-agent': 'Wget/1.16 (linux-gnu)'})
with open(save_to_path, "wb") as f:
for chunk in r.iter_content(chunk_size=4096):
if chunk:
f.write(chunk)
# load the label map
label_map = catalog.LABEL_MAP_CATALOG[dataset_name]
return lp.models.Detectron2LayoutModel(
config_path=config_file_path,
model_path=model_file_path,
label_map=label_map
)
model = load_model('lp://PubLayNet/faster_rcnn_R_50_FPN_3x/config') |
Same issue here! |
I refactored my code into a class which inherits the original Detectron2LayoutModel class. from layoutparser.models import Detectron2LayoutModel, detectron2
import requests
import copy
import os
class ExtractLayout(Detectron2LayoutModel):
def __init__(self,
config_path: str = 'lp://PubLayNet/faster_rcnn_R_50_FPN_3x/config',
*args,
**kwargs
):
"""
The following modified __init__ is to solve this issue:
https://github.com/Layout-Parser/layout-parser/issues/168
:param config_path: A path to the config file
"""
config_path_split = config_path.split('/')
dataset_name = config_path_split[-3]
model_name = config_path_split[-2]
model_url = Detectron2LayoutModel.MODEL_CATALOG[dataset_name][model_name]
config_url = detectron2.catalog.CONFIG_CATALOG[dataset_name][model_name]
if 'model' not in os.listdir():
os.mkdir('model')
config_file_path, model_file_path = None, None
for url in [model_url, config_url]:
filename = url.split('/')[-1].split('?')[0]
save_to_path = f"model/" + filename
if 'config' in filename:
config_file_path = copy.deepcopy(save_to_path)
if 'model_final' in filename:
model_file_path = copy.deepcopy(save_to_path)
if filename in os.listdir("model"):
continue
r = requests.get(url, stream=True, headers={'user-agent': 'Wget/1.16 (linux-gnu)'})
with open(save_to_path, "wb") as f:
for chunk in r.iter_content(chunk_size=4096):
if chunk:
f.write(chunk)
super().__init__(
config_path=config_file_path,
model_path=model_file_path,
*args,
**kwargs
) This way, if you have other parameters to change that are not relevant to my use, you can still call and modify them according Detectron2LayoutModel docs, within ExtractLayout class. # assuming the class is in a file named extract_layout.py
from .extract_layout import ExtractLayout
model = ExtractLayout(
config_path='lp://PubLayNet/faster_rcnn_R_50_FPN_3x/config', # only this part is explicitly expected
label_map={0: "Text", 1: "Title", 2: "List", 3: "Table", 4: "Figure"},
extra_config=["MODEL.ROI_HEADS.SCORE_THRESH_TEST", 0.75]
) |
This is what worked for me. You can download the .pth and .yaml files to some folder in your computer and then modify the paths as in this comment. The links to the files are here: https://github.com/Layout-Parser/layout-parser/blob/main/src/layoutparser/models/detectron2/catalog.py. Also, you can use wget -O config.yaml https://...... or wget -O model_final.pth https://....... to get the names as they should. |
+1 |
Getting the same error after renaming the path
|
I get the above assert when loading any config from the model zoo. The above example was thrown from the code below
The reason for the assert is that the local file is actually called "model.pth?dl=1"
I am using the latest version from "pip install layoutmanager", am running on an Amazon CentOS instance.
Any suggestions for a workaround would be greatly appreciated :-)
I can't copy the stack text, but attached is a screenshot
The text was updated successfully, but these errors were encountered: