mAP icon indicating copy to clipboard operation
mAP copied to clipboard

not even a problem

Open hello7623 opened this issue 5 years ago • 5 comments

Your code is very nice, thank you! But in the main.py, you seem to forgot import cv2 ?

hello7623 avatar Apr 07 '20 07:04 hello7623

Your code is very nice, thank you! But in the main.py, you seem to forgot import cv2 ?

you are right, but it does exist, the premise is that you have used the corresponding option.

# try to import OpenCV if the user didn't choose the option --no-animation
show_animation = False
if not args.no_animation:
    try:
        import cv2

        show_animation = True
    except ImportError:
        print("\"opencv-python\" not found, please install to visualize the results.")
        args.no_animation = True

# try to import Matplotlib if the user didn't choose the option --no-plot
draw_plot = False
if not args.no_plot:
    try:
        import matplotlib.pyplot as plt

        draw_plot = True
    except ImportError:
        print("\"matplotlib\" not found, please install it to get the resulting plots.")
        args.no_plot = True

zjZSTU avatar Apr 20 '20 02:04 zjZSTU

yes, I added that feature so that people were not required to have OpenCV in the beginning. The code should still work without OpenCV.

Cartucho avatar Apr 20 '20 06:04 Cartucho

yes, I added that feature so that people were not required to have OpenCV in the beginning. The code should still work without OpenCV.

emmmm, it exists , but it also work failed !!!

python main.py
99.18% = cucumber AP 
98.72% = eggplant AP 
95.30% = mushroom AP 
Traceback (most recent call last):
  File "/home/zj/test/mAP/main.py", line 743, in <module>
    img = cv2.imread(img_cumulative_path)
NameError: name 'cv2' is not defined
mAP = 97.73%

Process finished with exit code 1

because the file will save the pr-curve image, so may be it should be imported in the begining

"""
 Draw false negatives
"""
pink = (203,192,255)
for tmp_file in gt_files:
    ground_truth_data = json.load(open(tmp_file))
    #print(ground_truth_data)
    # get name of corresponding image
    start = TEMP_FILES_PATH + '/'
    img_id = tmp_file[tmp_file.find(start)+len(start):tmp_file.rfind('_ground_truth.json')]
    img_cumulative_path = output_files_path + "/images/" + img_id + ".jpg"
    img = cv2.imread(img_cumulative_path)                    《--------------------- here
    if img is None:
        img_path = IMG_PATH + '/' + img_id + ".jpg"
        img = cv2.imread(img_path)
    # draw false negatives
    for obj in ground_truth_data:
        if not obj['used']:
            bbgt = [ int(round(float(x))) for x in obj["bbox"].split() ]
            cv2.rectangle(img,(bbgt[0],bbgt[1]),(bbgt[2],bbgt[3]),pink,2)
    cv2.imwrite(img_cumulative_path, img)

zjZSTU avatar Apr 21 '20 02:04 zjZSTU

yes, I added that feature so that people were not required to have OpenCV in the beginning. The code should still work without OpenCV.

when import cv2 at begin, there will be another problem:

99.18% = cucumber AP 
98.72% = eggplant AP 
95.30% = mushroom AP 
Traceback (most recent call last):
  File "/home/zj/test/mAP/main.py", line 753, in <module>
    cv2.imwrite(img_cumulative_path, img)
cv2.error: OpenCV(4.2.0) ../modules/imgcodecs/src/loadsave.cpp:715: error: (-215:Assertion failed) !_img.empty() in function 'imwrite'

mAP = 97.73%

Process finished with exit code 1

img path doesn't exist

for tmp_file in gt_files:
    ground_truth_data = json.load(open(tmp_file))
    #print(ground_truth_data)
    # get name of corresponding image
    start = TEMP_FILES_PATH + '/'
    img_id = tmp_file[tmp_file.find(start)+len(start):tmp_file.rfind('_ground_truth.json')]
    img_cumulative_path = output_files_path + "/images/" + img_id + ".jpg"
    img = cv2.imread(img_cumulative_path)
    if img is None:
        img_path = IMG_PATH + '/' + img_id + ".jpg"
        img = cv2.imread(img_path)
    # draw false negatives
    for obj in ground_truth_data:
        if not obj['used']:
            bbgt = [ int(round(float(x))) for x in obj["bbox"].split() ]
            cv2.rectangle(img,(bbgt[0],bbgt[1]),(bbgt[2],bbgt[3]),pink,2)
    cv2.imwrite(img_cumulative_path, img)            《------------------------------- here 

zjZSTU avatar Apr 21 '20 02:04 zjZSTU

I forgot to check if cv2 exists in that part of the code. Now it should work even without cv2 installed.

Cartucho avatar Apr 21 '20 13:04 Cartucho