当前位置: 首页>>代码示例>>Python>>正文


Python ClarifaiApi.tag方法代码示例

本文整理汇总了Python中clarifai.client.ClarifaiApi.tag方法的典型用法代码示例。如果您正苦于以下问题:Python ClarifaiApi.tag方法的具体用法?Python ClarifaiApi.tag怎么用?Python ClarifaiApi.tag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在clarifai.client.ClarifaiApi的用法示例。


在下文中一共展示了ClarifaiApi.tag方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post_clarifai

# 需要导入模块: from clarifai.client import ClarifaiApi [as 别名]
# 或者: from clarifai.client.ClarifaiApi import tag [as 别名]
def post_clarifai(imagepath):
    """
    @return person(bool), pretty(bool), tags(list)
    """
    print "START_CLARIFAI"
    app_id = "J-1HVOns4pAe61vumq7NFHvf-TpHXrX54WaKyVyD"
    app_secret = "sY9cM9tyklkhcNv_6gWPs9_ihqv9Amxw5H_1wxiH"
    api = ClarifaiApi(app_id, app_secret)
    with open(imagepath,'rb') as image_file:
        res0 = api.tag(image_file, select_classes="bottle,crow,food")
        #print json.dumps(res0, indent=2)
        
        res0_tags = res0.get("results",{})[0].get("result",{}).get("tag",{})
        #res0_classes = res0_tags.get("classes")
        bottle_probs = res0_tags.get("probs")[0]
        crow_probs = res0_tags.get("probs")[1]
        food_probs = res0_tags.get("probs")[2]
        #print "food_probs"
        #print food_probs
        #if "bird" in res0_classes or "bottle" in res0_classes:
        if (bottle_probs > 0.15):  
            print "bottle"
            return False, "pretty" in res0_classes, res0_classes, u"おーいお茶"
        elif (crow_probs > 0.15):
            print "crow"
            return False, "pretty" in res0_classes, res0_classes, None
        elif (food_probs > 0.3):
            print "food"
            return False, "pretty" in res0_classes, res0_classes, u"チョコパイ"
        res1 = api.tag(image_file, select_classes="pretty,smile")
        print json.dumps(res1, indent=2)
        res1_tags = res1.get("results",{})[0].get("result",{}).get("tag",{})
        res1_classes = res1_tags.get("classes")
        # TODO pretty thre
        pretty_val = res1_tags.get("probs")[0]
	smile_val = res1_tags.get("probs")[1]
        print "PRETTY VAL=%s" % pretty_val
        
        #data["person"], data["pretty"], data["tags"], data["item"]
        return True, pretty_val>0.5, res0_classes, None
开发者ID:r-stack,项目名称:team-c,代码行数:42,代码来源:mamorule.py

示例2: check_pretty

# 需要导入模块: from clarifai.client import ClarifaiApi [as 别名]
# 或者: from clarifai.client.ClarifaiApi import tag [as 别名]
def check_pretty(imageurl):
    api = ClarifaiApi()
    #api.set_model("")
    if imageurl.startswith('http'):
        response = api.tag_image_urls(imageurl, select_classes="pretty,human")
    elif os.path.isdir(imageurl):
        response = tag_images_in_directory(imageurl)
    elif os.path.isfile(imageurl):
        with open(imageurl,'rb') as image_file:
            response = api.tag(image_file, select_classes="pretty,human,man,woman")
    else:
        raise Exception("Must input url, directory path, or file path")
    
    print json.dumps(response, indent=2)
    return response
开发者ID:r-stack,项目名称:team-c,代码行数:17,代码来源:prettyFinder.py

示例3: main

# 需要导入模块: from clarifai.client import ClarifaiApi [as 别名]
# 或者: from clarifai.client.ClarifaiApi import tag [as 别名]
def main(argv):
  if len(argv) > 1:
    imageurl = argv[1]
  else:
    imageurl = 'http://clarifai-img.s3.amazonaws.com/test/toddler-flowers.jpeg'

  api = ClarifaiApi()
  #api.set_model("")
  if imageurl.startswith('http'):
    response = api.tag_image_urls(imageurl)
  elif os.path.isdir(imageurl):
    response = tag_images_in_directory(imageurl)
  elif os.path.isfile(imageurl):
    with open(imageurl,'rb') as image_file:
      response = api.tag(image_file, select_classes="pretty,man,woman")
  else:
    raise Exception("Must input url, directory path, or file path")

  resultCode = json.dumps(response, indent=2
                          )
  print resultCode
开发者ID:r-stack,项目名称:team-c,代码行数:23,代码来源:prettyFinder.py


注:本文中的clarifai.client.ClarifaiApi.tag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。