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


Python ClarifaiApi.get_info方法代码示例

本文整理汇总了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))
开发者ID:DasilvaKareem,项目名称:HackMit2015,代码行数:73,代码来源:extract_tags.py

示例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)
开发者ID:yatingupta10,项目名称:clarifai-python,代码行数:7,代码来源:test_client.py


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