zzh8829 / yolov3-tf2

YoloV3 Implemented in Tensorflow 2.0
MIT License
2.51k stars 909 forks source link

UnparsedFlagAccessError: Trying to access flag --yolo_max_boxes before flags were parsed. #309

Open bessszilard opened 4 years ago

bessszilard commented 4 years ago

Hello! I run this command successfully.

!python convert.py --weights /content/drive/My\ Drive/20200726/yolov3_backup/yolov3_best.weights --output /content/yolov3.tf --num_classes 5

After that I tried to load the model in my code:

import numpy as np
from yolov3_tf2.models import YoloV3, YoloV3Tiny
from yolov3_tf2.utils import load_darknet_weights
import tensorflow as tf

num_classes = 5
weights = '/content/drive/My Drive/20200726/yolov3_backup/yolov3_best.weights'

yolo = YoloV3(classes=num_classes)
load_darknet_weights(yolo, weights)

yolo.summary()

And I got this error:

---------------------------------------------------------------------------

UnparsedFlagAccessError                   Traceback (most recent call last)

<ipython-input-22-4229ca460a67> in <module>()
      3 #     tf.config.experimental.set_memory_growth(physical_devices[0], True)
      4 
----> 5 yolo = YoloV3(classes=num_classes)
      6 yolo.summary()
      7 logging.info('model created')

5 frames

/usr/local/lib/python3.6/dist-packages/absl/flags/_flagvalues.py in __getattr__(self, name)
    489         # get too much noise.
    490         logging.error(error_message)
--> 491       raise _exceptions.UnparsedFlagAccessError(error_message)
    492 
    493   def __setattr__(self, name, value):

UnparsedFlagAccessError: Trying to access flag --yolo_max_boxes before flags were parsed.

I don't understand why I got this error, because the convert.py script loads the model similarly way to my code.

parthkhopkar commented 4 years ago

The absl module first needs to parse the flags before they can be used. Please refer to the FAQ at the bottom of this page: https://abseil.io/docs/python/guides/flags#faqs

bessszilard commented 4 years ago

@parthkhopkar thanks for your answer, but I don't understand the linked blog post. I want to run this in a jupyter notebook. Can you give me an example code?

Ajinkya-Bhandare commented 4 years ago

@bessszilard I was able to solve this by adding FLAGS(sys.argv)

just after importing libraries in models.py

escudero commented 4 years ago

@bessszilard, follow my complete example

yolo_max_boxes = 100
yolo_iou_threshold = 0.5
yolo_score_threshold = 0.5

from absl.flags import FLAGS
FLAGS([
    './program',
    f'--yolo_max_boxes={yolo_max_boxes}',
    f'--yolo_iou_threshold={yolo_iou_threshold}',
    f'--yolo_score_threshold={yolo_score_threshold}'
])
escudero commented 3 years ago

Hi,

You need to import this class first. import yolov3_tf2.models

On Thu, Dec 3, 2020 at 3:11 PM yaelhdd notifications@github.com wrote:

Hi, while stomping on the same problem as @bessszilard https://github.com/bessszilard, I have tried both @escudero https://github.com/escudero and @Ajinkya-Bhandare https://github.com/Ajinkya-Bhandare solutions. With @escudero https://github.com/escudero I get: "UnrecognizedFlagError: Unknown command line flag 'yolo_max_boxes' " With @Ajinkya-Bhandare https://github.com/Ajinkya-Bhandare I get: NameError: name 'sys' is not defined.

If any of you would extend on their solution (@bessszilard https://github.com/bessszilard perhaps you found anything else or one of these worked well).

Thanks so much

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/zzh8829/yolov3-tf2/issues/309#issuecomment-738187297, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAHXJETODBBWMICBBP6BPLSS7IEVANCNFSM4PKMEUNA .