本文整理汇总了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
示例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, []
示例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
示例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']
示例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)
示例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)
示例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
示例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
示例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
示例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