turing可视化搜索和可视化相似推荐python的api库
turing-api的Python项目详细描述
Turing Python库
Turing VisualSearch和VisualSimon推荐的Python API库。rest api文档可以在这里找到:https://api.turingiq.com/doc/
设置
这个包可以通过pip获得,可以使用以下命令安装。
pip3 install turing-api
初始化
将visualAPI
类导入如下。
fromturing_api.lib.visualAPIimportVisualAPI
可以使用以下参数初始化VisualAPI
类。
api_key='your_api_key'# You can get API key when you login at: https://www.turingiq.com/loginmode='live'# the mode can be either `live` or `sandbox`. Default mode is `live`.visual_api=VisualAPI(api_key,mode)
自动翻滚
检测图像中的对象并获取检测对象周围的边界框。
# image_url is required field.image_url="https://example.com/image_url.jpg"# now let's call the API.response=visual_api.autocrop(image_url)
该方法返回的边界框可用于视觉搜索,提高视觉搜索质量。
插入
你需要在我们的索引中插入图片来查询它们。insert函数可以如下编写。
# id is required field.id='some_product_id'# image_url is required field.image_url="https://example.com/image_url.jpg"# filters argument is optional. You can specify upto 3 filters as per example given below.# Filters can be useful when querying images from our index. You can apply any filter# as per your requirement.filters={"filter1":"onefilter","filter2":"twofilter","filter3":"threefilter"}# metadata is optional. You can pass additional information about your image which will be# returned when you query image from our index.metadata={"title":"Image Title"}# now let's call the API.response=visual_api.insert(id,image_url,filters,metadata)
更新
如果需要更新索引图像的信息,可以使用更新功能。如果对尚未建立索引的id调用update函数,它会将图像插入索引。
# id is required field. Provide id for which you need to update the information.id='some_product_id'# image_url is optional field. You can pass `null` if you would like to keep URL unchanged.image_url="https://example.com/image_url.jpg"# filters argument is optional. You can specify upto 3 filters as per example given below.# Filters can be useful when querying images from our index. You can apply any filter# as per your requirement. The filters you provide here will be overwritten.filters={"filter1":"onefilter","filter2":"twofilter","filter3":"threefilter"}# metadata is optional. You can pass additional information about your image which will be# returned when you query image from our index. Existing metadata values will be overwritten# based on keys supplied to this array.metadata={"title":"Image Title"}# now let's call the API.response=visual_api.update(id,image_url,filters,metadata)
删除
使用此方法可以从索引中删除图像。
# id is required field.id='some_product_id'# now let's call the API.response=visual_api.delete(id)
视觉搜索
可视化搜索可用于基于查询图像搜索索引图像。
# image_url is required field. The API will perform visual search on the image and returnimage_url="https://example.com/image_url.jpg"# crop_box is optional field. You can supply empty array if you don't want to specify crop box.# The format of crop box is [xmin, ymin, xmax, ymax]crop_box=[188,256,656,928]# filters argument is optional. You can specify upto 3 filters.# For example, if you specify filter1 = "nike", it will only return images which are indexed with# "nike" as filter1.filters={"filter1":"nike"}# now let's call the API.response=visual_api.search(image_url,crop_box,filters)
视觉推荐
视觉推荐提供视觉上相似的图像推荐,可用于在电子商务网站上显示推荐小部件,从而大大提高CTR和转换率。
# image_url is required field. The API will perform visual search on the image and returnid="some_product_id"# filters argument is optional. You can specify upto 3 filters.# For example, if you specify filter1 = "nike", it will only return images which are indexed with# "nike" as filter1.filters={"filter1":"nike"}# now let's call the API.response=visual_api.recommendations(id,filters)
运行测试
API_KEY=api_key python3 test/visualAPITest.py