六行代码完成图像识别(Python)
使用Python完成了相册文件的去重,但是还有很多相似的照片,可能同一个场景下拍了好多张,所以今天研究一下AI的东西,看看能不能用AI识别重复图片...
我研究之后发现有个ImageAI库,应该能完成这个活,所以我需要先配置好环境,但是第一步就出了大问题:
PS C:\Users\imBobby> pip install tensorflow -i https://pypi.tuna.tsinghua.edu.cn/simple/Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/ERROR: Could not find a version that satisfies the requirement tensorflowERROR: No matching distribution found for tensorflow
安装TensorFlow就死活安不上,经过研究后我发现...TF不支持python3.9...于是:
终于成了:
接下来需要安装这么多依赖:
pip install numpypip install scipypip install opencv-pythonpip install pillowpip install matplotlibpip install h5pypip install keraspip install ImageAI
全都安完了,然后再去GitHub下载个模型:
https://github.com/OlafenwaMoses/ImageAI/releases
写几行代码试试咯:
from imageai.Detection import ObjectDetectiondetector = ObjectDetection()detector.setModelTypeAsRetinaNet()detector.setModelPath(r'C:\Users\imBobby\Downloads\resnet50_coco_best_v2.1.0.h5')# 以上为下载的模型存储路径detector.loadModel()detection = detector.detectObjectsFromImage(input_image=r"E:\AITest\1D34F4B0-8ECF-4719-8583-013AF92B3609.JPG", output_image_path="E:\AITest\outputFIle.jpg")# 输入文件与输出文件
执行一下看看测试结果:
兄弟情
我是特种兵
酒醉的利纳斯
狂野男孩
好像还行啊,但是并没有解决我的问题,这玩意也没法判断图片相似度啊...改日在继续研究吧家人们...
觉得好看的铁铁们可以点下在看,点点赞:
