Skip to content
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

local variable 'model_files' referenced before assignment #66

Closed
alic-xc opened this issue May 31, 2021 · 3 comments
Closed

local variable 'model_files' referenced before assignment #66

alic-xc opened this issue May 31, 2021 · 3 comments

Comments

@alic-xc
Copy link

alic-xc commented May 31, 2021

Hi guys,
Having successfully training my model for the past 1 week. i have a problem trying to evaluate them.

import pixellib
from pixellib.custom_train import instance_custom_training


train_maskrcnn = instance_custom_training()
train_maskrcnn.modelConfig(network_backbone = "resnet50", num_classes= 1)
train_maskrcnn.load_dataset("fingerlings")
train_maskrcnn.evaluate_model("mask_rccn_models")

This is the error

Using resnet50 as network backbone For Mask R-CNN model
---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
<ipython-input-20-55777605efed> in <module>()
      6 train_maskrcnn.modelConfig(network_backbone = "resnet50", num_classes= 1)
      7 train_maskrcnn.load_dataset("fingerlings")
----> 8 train_maskrcnn.evaluate_model("mask_rccn_models")

/usr/local/lib/python3.7/dist-packages/pixellib/custom_train.py in evaluate_model(self, model_path, iou_threshold)
    132         if os.path.isdir(model_path):
    133             model_files = sorted([os.path.join(model_path, file_name) for file_name in os.listdir(model_path)])
--> 134 
    135         for modelfile in model_files:
    136             if str(modelfile).endswith(".h5"):

UnboundLocalError: local variable 'model_files' referenced before assignment

I need your help. will appreciate any effort

@ayoolaolafenwa
Copy link
Owner

@alic-xc you used the wrong name to reference the path to the saved models.

train_maskrcnn.evaluate_model("mask_rccn_models")

The name of the default path to saved models is mask_rcnn_models not mask_rccn_models.

Confirm by checking the name of the path to saved models in your directory, you will realize that the path name does not match the name referenced in your code.

Correct code corresponding to the default path of the saved models:

train_maskrcnn.evaluate_model("mask_rcnn_models")

Note: You can change the name of the models' path to any name you want, but ensure that you reference that exact name given in your code.

@alic-xc
Copy link
Author

alic-xc commented Jun 1, 2021

@ayoolaolafenwa Sure. Thanks. Working now.

@alic-xc alic-xc closed this as completed Jun 1, 2021
@MarkWijkhuizen
Copy link

MarkWijkhuizen commented Oct 20, 2021

I encountered the same problem. The reason for the typo is the typo in the awesome tutorial Custom Instance Segmentation Training With 7 Lines Of Code.

Would prevent a lot of frustrations if this typo could be corrected 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants