国外某集成度极高的机器学习图片识别

Muxxs
Muxxs 2018年07月08日
  • 在其它设备中阅读本文章

简单的实现:

 

#coding=utf-8
from imageai.Detection import ObjectDetection
from imageai.Prediction import ImagePrediction
import urllib.parse, urllib.request,re,json,hashlib,random
appid = '20180617000177418'
secretKey = 'j7GDt47VkhMz3eUFB9Qb'
url_baidu = 'http://api.fanyi.baidu.com/api/trans/vip/translate'
def translateBaidu(text, f='en', t='zh'):
    salt = random.randint(32768, 65536)
    sign = appid + text + str(salt) + secretKey
    sign = hashlib.md5(sign.encode()).hexdigest()
    url = url_baidu + '?appid=' + appid + '&q=' + urllib.parse.quote(text) + '&from=' + f + '&to=' + t + \
    '&salt=' + str(salt) + '&sign=' + sign
    response = urllib.request.urlopen(url)
    content = response.read().decode('utf-8')
    data = json.loads(content)
    result = str(data['trans_result'][0]['dst'])
    print(result)
import os
while True:
    pic_url=input("请输入图片地址:")
    pic_url=pic_url.replace(" ","")
    filename=pic_url.split("/")[-1].split(".")[0]
    print(filename)
    detector = ObjectDetection()
    detector.setModelTypeAsRetinaNet()
    detector.setModelPath("./Desktop/center_weixin/resnet50_coco_best_v2.0.1.h5")
    detector.loadModel()
    detections = detector.detectObjectsFromImage(input_image=os.path.join(pic_url.replace("/Users/wangjiao",".")), output_image_path=os.path.join("./Desktop/"+filename+"_out.jpg"))
    alltext=""
    from PIL import Image, ImageDraw,ImageFont
    im = Image.open(os.path.join("./Desktop/"+filename+"_out.jpg")).convert('RGBA')
    #txt=Image.new('RGBA', im.size, (0,0,0,0))
    fnt=ImageFont.truetype("./Desktop/center_weixin/font.ttc", 20)
    d=ImageDraw.Draw(im)
    d.text((0,0), "muxxs.com",font=fnt, fill=(255,0,0))
    d=ImageDraw.Draw(im)
    im.save(os.path.join("./Desktop/"+filename+"_out.png"))
    print("sucess")

模型文件明天上传

实现的结果