Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
635 views
in Technique[技术] by (71.8m points)

Matplotlib - sequence is off when using plt.imshow()

I write a dog-classifier in a Jupyter notebook that, every time a dog is detected in an image, should show the image and print some text describing it. Somehow, the images are always displayed after all the text was printed, no matter in which order I put plt.imshow() and print(). Does anybody know why this is the case?

Thank you!

Here is my code-snippet:

for i in range (0, 1,1):

    all_counter+=1

    if dog_detector(dog_files_short[i]):

        img = image.load_img(dog_files_short[i], target_size=(224, 224))
        plt.show()
        plt.imshow(img)
        time.sleep(5)
        print("That's a dog!!!!")
        dog_counter+=1
        print("______________")

    else: 

        print("______________")
        img = image.load_img(dog_files_short[i], target_size=(224, 224))
        plt.show()
        plt.imshow(img)
        print("No Doggo up here :(")
        print(ResNet50_predict_labels(dog_files_short[i]))
        print("______________")

print((dog_counter/all_counter)*100, "% of the dog pictures are classified as dogs")

The output is like this:

example output

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I tried this in my ipython notebook, if I first call plt.imshow(img) and plt.show() right after I get the image first and the text after.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...