am_dot_com

IA 2022-12-14

Dec 14th, 2022 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #class_animals.py #classification of images of animals
  2.  
  3. import os #operating system
  4. from amutil_ai import AmUtilAi
  5.  
  6. dirWithImages = "./an2"
  7. listOfNamesOfAllFilesInDir =\
  8. os.listdir(
  9. dirWithImages
  10. )
  11. #print(listOfNamesOfAllFilesInDir)
  12.  
  13. for filename in listOfNamesOfAllFilesInDir:
  14. bJpg = filename.find(".jpg")!=-1
  15. bPng = filename.find(".png")!=-1
  16. bImage = bJpg or bPng
  17. if (bImage):
  18. strImagePath = f"{dirWithImages}/{filename}"
  19. print (f"Will classify the image @{strImagePath}")
  20. classificationResult =\
  21. AmUtilAi.kerasClassify(
  22. pStrImagePath=strImagePath,
  23. pbStrClassificationTop1=True,
  24. pbShowImageWithOverlayedClassificationRightAfterPredicion=True
  25. )
  26. input("Press ENTER to continue") #pause
  27.  
  28. #TODO rename
  29. AmUtilAi.renameImageWithPrefixingTopClassification(
  30. pStrParentDir=dirWithImages,
  31. pStrImageFileName=filename,
  32. pStrClassification=classificationResult
  33. )
  34. #if
  35. else:
  36. print(f"skipped {filename} because it is NOT an image.")
  37. #for
Advertisement
Add Comment
Please, Sign In to add comment