本文整理汇总了Python中clarifai.client.ClarifaiApi.get_info方法的典型用法代码示例。如果您正苦于以下问题:Python ClarifaiApi.get_info方法的具体用法?Python ClarifaiApi.get_info怎么用?Python ClarifaiApi.get_info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类clarifai.client.ClarifaiApi
的用法示例。
在下文中一共展示了ClarifaiApi.get_info方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Video_Tag_Extract
# 需要导入模块: from clarifai.client import ClarifaiApi [as 别名]
# 或者: from clarifai.client.ClarifaiApi import get_info [as 别名]
class Video_Tag_Extract():
def __init__(self, video_name):
self.working_root = '..'
self.videos_root = '../training_videos'
self.images_root = '../training_images'
self.json_root = '../jsons'
self.video_name = video_name
self.modulus = 20
self.api = ClarifaiApi()
def extract_images_from_video(self, video_start, video_end, job_id):
"""
input
self.video_name
output
json file
"""
# set up
video_range = range(video_start, video_end)
cap = cv2.VideoCapture(os.path.join(self.videos_root, self.video_name))
num_frames = cap.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT)
fps = cap.get(cv2.cv.CV_CAP_PROP_FPS)
self.modulus = int(1.5*fps)
print self.modulus
width = cap.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)
height = cap.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)
print width
print height
# assert False
cur_frame = 0
while cur_frame < num_frames:
print cur_frame
has_frame, frame = cap.read() # frame is (height, width, channels)
if cur_frame in video_range:
cv2.imshow('frame', frame)
# write frame
if (cur_frame - video_start) % self.modulus == 0:
img_filename = os.path.join(self.images_root, self.video_name[:self.video_name.find('.mp4')] + '_' + str(cur_frame) + '_job_id=' + str(job_id) + '.jpg')
cv2.imwrite(img_filename, frame)
print 'Written'
k = cv2.waitKey(30) & 0xff
if k == 27:
break
cur_frame += 1
cv2.destroyAllWindows()
cap.release()
def analyze_images(self, job_id):
# analyze images in batch
image_list = [x for x in os.listdir(self.images_root) if 'job_id=' + str(job_id) + '.jpg' in x][:self.api.get_info()['max_batch_size']]
result = self.api.tag_images([open(os.path.join(self.images_root, x)) for x in image_list])['results']
info = {}
for idx in range(len(result)):
info[str(idx)] = result[idx]['result']['tag']
with open('data.json', 'w') as fp:
json.dump(info, fp)
def remove_images(self, video_start, video_end, job_id):
image_list = [x for x in os.listdir(self.images_root) if 'job_id=' + str(job_id) + '.jpg' in x]#[:self.api.get_info()['max_batch_size']]
for img_name in image_list:
os.system('rm ' + os.path.join(self.images_root, img_name))
示例2: test_get_info
# 需要导入模块: from clarifai.client import ClarifaiApi [as 别名]
# 或者: from clarifai.client.ClarifaiApi import get_info [as 别名]
def test_get_info(self):
api = ClarifaiApi()
response = api.get_info()
self.assertTrue(response.get("api_version"))
self.assertTrue(len(response) > 0)