qqwweee / keras-yolo3

A Keras implementation of YOLOv3 (Tensorflow backend)
MIT License
7.14k stars 3.45k forks source link

Command line FLAGS != vars(YOLO) #271

Open Jacob-Stevens-Haas opened 5 years ago

Jacob-Stevens-Haas commented 5 years ago

After training weights trained_weights_final.h5 on new data, I tried running
python yolo_video.py --model "logs/000/trained_weights_final.h5" --image.
After the normal instantiation of the model & spinning up the GPU, Yolo printed:
model_data/yolo.h5 model, anchors, and classes loaded. I found that this was because the command line flags weren't quite working. They are passed to the constructor for YOLO, but they don't match up verbatim with the default attribute keys. When the YOLO object dictionary is updated with the command line flags, instead of overwriting the defaults, the flags get added as new entries. Subsequent calls to the object reference the default attributes.

Specifically, yolo_video.py calls YOLO(**vars(FLAGS)). Then, the constructor in yolo.py begins:

    def __init__(self, **kwargs):
        self.__dict__.update(self._defaults) # set up default values
        self.__dict__.update(kwargs) # and update with user overrides

But you can see that the defaults in yolo.py

    _defaults = {
        "model_path": 'model_data/yolo.h5',
        "anchors_path": 'model_data/yolo_anchors.txt',
        "classes_path": 'model_data/coco_classes.txt',
        "score" : 0.3,
        "iou" : 0.45,
        "model_image_size" : (416, 416),
        "gpu_num" : 1,
    }

do not share the same names as

parser.add_argument('--model', type=str, ...
parser.add_argument('--anchors', type=str, ...
parser.add_argument('--classes', type=str, ...

and are therefore not updated. You can verify this by adding a line to check self.__dict__ in the YOLO constructor after creation. model_path, anchors_path, and classes_path all remain the defaults even if command line arguments are passed to override them.

@tanakataiki @philtrade - I saw you folks added the last commit with command line. Can you let me know if I'm using the command correctly? If so, I'm happy to open a PR to change the command line arguments to fix the issue.

iris-qq commented 5 years ago

i also found this problem,my approach is to modify yolo_video.py


        '--model_path', type=str,
        help='path to model weight file, default ' +
        YOLO.get_defaults("model_path")
    )
      parser.add_argument(
        '--anchors_path', type=str,
        help='path to anchor definitions, default ' +
        YOLO.get_defaults("anchors_path")
    )
    parser.add_argument(
        '--classes_path', type=str,
        help='path to class definitions, default ' +
        YOLO.get_defaults("classes_path")
    )```

but the model didn't effective.
can you  help me?
@Jacob-Stevens-Haas 
philtrade commented 5 years ago

Dear all,

Sorry for the late reply -- I am currently occupied by other projects, and thus unfortunately do not have spare cycles to keras/yolo3. I appreciate your findings and feedback, please feel free to play/hack/test around, and am sure the repo owner would entertain your pull requests.

I hope to be back on this project at some point.

Best regards, and Happy New Year!

Phil

On Fri, Dec 28, 2018 at 2:22 PM Atlantis notifications@github.com wrote:

i also found this problem,my approach is to modify yolo_video.py `parser.add_argument( '--model_path', type=str, help='path to model weight file, default ' + YOLO.get_defaults("model_path") )

parser.add_argument( '--anchors_path', type=str, help='path to anchor definitions, default ' + YOLO.get_defaults("anchors_path") )

parser.add_argument( '--classes_path', type=str, help='path to class definitions, default ' + YOLO.get_defaults("classes_path") )`

but the model didn't effective. can you help me? @Jacob-Stevens-Haas https://github.com/Jacob-Stevens-Haas

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/qqwweee/keras-yolo3/issues/271#issuecomment-450298487, or mute the thread https://github.com/notifications/unsubscribe-auth/AS90fnE2hZjvkUK3ssDm9loComtcs4iIks5u9biTgaJpZM4YO5o2 .