Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #class_animals.py #classification of images of animals
- import os #operating system
- from amutil_ai import AmUtilAi
- dirWithImages = "./an2"
- listOfNamesOfAllFilesInDir =\
- os.listdir(
- dirWithImages
- )
- #print(listOfNamesOfAllFilesInDir)
- for filename in listOfNamesOfAllFilesInDir:
- bJpg = filename.find(".jpg")!=-1
- bPng = filename.find(".png")!=-1
- bImage = bJpg or bPng
- if (bImage):
- strImagePath = f"{dirWithImages}/{filename}"
- print (f"Will classify the image @{strImagePath}")
- classificationResult =\
- AmUtilAi.kerasClassify(
- pStrImagePath=strImagePath,
- pbStrClassificationTop1=True,
- pbShowImageWithOverlayedClassificationRightAfterPredicion=True
- )
- input("Press ENTER to continue") #pause
- #TODO rename
- AmUtilAi.renameImageWithPrefixingTopClassification(
- pStrParentDir=dirWithImages,
- pStrImageFileName=filename,
- pStrClassification=classificationResult
- )
- #if
- else:
- print(f"skipped {filename} because it is NOT an image.")
- #for
Advertisement
Add Comment
Please, Sign In to add comment