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


Python rest.Image方法代码示例

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


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

示例1: img_has_cat

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import Image [as 别名]
def img_has_cat(filename):
    app = ClarifaiApp(api_key=settings.CLARIFAI_API_KEY)
    model = app.models.get("general-v1.3")
    try:
        image = Image(file_obj=open(filename, 'rb'))
        result = model.predict([image])
        try:
            items = result['outputs'][0]['data']['concepts']
            for item in items:
                if item['name'] == 'cat':
                    return True
            else:
                return False
        except (IndexError):
            return False
    except (client.ApiError, FileNotFoundError):
        return False 
开发者ID:korneevm,项目名称:simplebot,代码行数:19,代码来源:cat_checker.py

示例2: check_image

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import Image [as 别名]
def check_image(browser, clarifai_api_key, img_tags, logger, full_match=False):
    """Uses the link to the image to check for invalid content in the image"""
    clarifai_api = ClarifaiApp(api_key=clarifai_api_key)

    img_link = get_imagelink(browser)
    # Uses Clarifai's v2 API
    model = clarifai_api.models.get('general-v1.3')
    image = ClImage(url=img_link)
    result = model.predict([image])
    clarifai_tags = [concept.get('name').lower() for concept in result[
        'outputs'][0]['data']['concepts']]

    for (tags, should_comment, comments) in img_tags:
        if should_comment:
            if given_tags_in_result(tags, clarifai_tags, full_match):
                return True, comments
        else:
            if given_tags_in_result(tags, clarifai_tags, full_match):
                logger.info('Not Commenting, Possibly contains: "{}".'.format(', '.join(list(set(clarifai_tags)&set(tags)))))
                return False, []

    return True, [] 
开发者ID:timgrossmann,项目名称:InstaPy,代码行数:24,代码来源:clarifai_util.py

示例3: checkPhoto

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import Image [as 别名]
def checkPhoto(pictureURL, tag):
	resp = twiml.Response()
	photoApp = ClarifaiApp()
	#all concepts attached to the item specified in photo database (i.e. answer key)
	conceptGoals = [str(x) for x in mongo.db.photoGoals.find_one({"item":tag})["concepts"]]
	model = photoApp.models.get(tag)
	image = ClImage(url = pictureURL)
	#all data associated with each concept: id, name, appid, and value
	predictionData = json.loads(str(model.predict([image])))['outputs']['data']['concepts']
	userConcepts = []
	for x in predictionData:
		userConcepts.append(x[1])
	#all concepts included in user's photo
	conceptsPresent = conceptGoals.intersection(userConcepts)
	numbers = []
	for x in conceptsPresent:
		#threshold for approval is 51%
		probability = predictionData["value"]
		if probability > 0.5:
			numbers.append(probability)
	if numbers.length > 0:
		return True
	else:
		return False 
开发者ID:sara,项目名称:PhotoHunt,代码行数:26,代码来源:views.py

示例4: predict_image_bias

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import Image [as 别名]
def predict_image_bias(url):
    app = get_clarifai_api()
    model = app.models.get('news-photos')
    image = ClImage(url=url)
    data = model.predict([image])
    concepts = get_concept_scores(data)

    if concepts['bias'] > concepts['neutral']:
        return 'bias', concepts['bias']
    else:
        return 'neutral', concepts['neutral'] 
开发者ID:mariru,项目名称:fakenews,代码行数:13,代码来源:classify.py

示例5: bulk_upload

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import Image [as 别名]
def bulk_upload(urls, concepts, not_concepts, app):
    # Bulk Import Images API
    images = []
    for url in urls:
        img = ClImage(url=url, concepts=concepts, not_concepts=not_concepts)
        images.append(img)

    app.inputs.bulk_create_images(images) 
开发者ID:mariru,项目名称:fakenews,代码行数:10,代码来源:clarifai_api.py

示例6: predict

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import Image [as 别名]
def predict(url):
    app = get_clarifai_api()
    model = app.models.get('news-photos')
    image = ClImage(url=url)
    data = model.predict([image])
    return get_concept_scores(data) 
开发者ID:mariru,项目名称:fakenews,代码行数:8,代码来源:clarifai_api.py

示例7: create_image_set

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import Image [as 别名]
def create_image_set(img_path, concepts):
    images = []
    for file_path in glob(os.path.join(img_path, '*.jpg')):
    	print(file_path)
        img = ClImage(filename=file_path, concepts=concepts)
        images.append(img)

    return images 
开发者ID:Mehty,项目名称:HairStyler,代码行数:10,代码来源:Heart.py

示例8: create_image_set

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import Image [as 别名]
def create_image_set(img_path, concepts):
    images = []
    for file_path in glob(os.path.join(img_path, '*.jpg')):
        print(file_path)
        img = ClImage(filename=file_path, concepts=concepts)
        images.append(img)

    print images 
开发者ID:Mehty,项目名称:HairStyler,代码行数:10,代码来源:train.py

示例9: make_photo_collection

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import Image [as 别名]
def make_photo_collection(path, searchItem):
	photoCollection = []
	for path in glob (os.path.join(path, '*.jpg')):
		with flaskApp.app_context():
			concepts = [str(r) for r in mongo.db.photoGoals.find_one({"item": searchItem})["concepts"]]
			photo = ClImage(filename=path, concepts = photoConcepts)
			photoCollection.append(photo)
	return photoCollection 
开发者ID:sara,项目名称:PhotoHunt,代码行数:10,代码来源:photoModels.py

示例10: checkPhoto

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import Image [as 别名]
def checkPhoto(pictureURL, tag):
	resp = twiml.Response()
	photoApp = ClarifaiApp()
	#all concepts attached to the item specified in photo database (i.e. answer key)
	with app.app_context():
		conceptGoals = mongo.db.photoGoals.find_one({"item":tag})
	model = photoApp.models.get(tag)
	image = ClImage(url='https://samples.clarifai.com/metro-north.jpg')
	#all data associated with each concept: id, name, appid, and value
	predictionData = model.predict([image])['outputs'][0]['data']['concepts']
	#['outputs']['data']['concepts']
	#predictionData = predictionData.replace("'", '"')
	#dataDict = json.loads(predictionData)
	#concepts = predictionData.get('outputs')
	print(predictionData)
	#userConcepts = []
	#for x in predictionData:
	#	userConcepts.append(x[1])
	#all concepts included in user's photo
	#conceptsPresent = conceptGoals.intersection(userConcepts)
	#numbers = []
	#for x in conceptsPresent:
		#threshold for approval is 51%
	#	probability = predictionData["value"]
	#	if probability > 0.5:
	#		numbers.append(probability)
	#if numbers.length > 2:
	#	return True
	#else:
	#	return False 
开发者ID:sara,项目名称:PhotoHunt,代码行数:32,代码来源:viewsTester.py


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