當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。