我在 Jupyter 笔记本中编写了一个狗分类器,每次在图像中检测到狗时,它都应该显示该图像并打印一些描述该图像的文本。不知何故,无论我按什么顺序放置plt.imshow()和,图像总是在打印所有文本后显示print()。有谁知道为什么会这样?
谢谢你!
这是我的代码片段:
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")
Run Code Online (Sandbox Code Playgroud)
输出是这样的:
