Example #1
0
    def test_upload_images_tag_exists(self):
        self.setup(n_data=10)

        def get_tags_callback(request):
            return (
                200,
                [],
                json.dumps([{'name': 'initial-tag'}, {'name': 'other-tag'}])
            )
        
        def get_quota_callback(request):
            return (
                200,
                [],
                json.dumps({'maxDatasetSize': 25000})
            )

        responses.add_callback(
            responses.GET, self.gettag_url,
            callback=get_tags_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET, self.getquota_url,
            callback=get_quota_callback,
            content_type='application/json'
        )

        with self.assertRaises(RuntimeError):
            api.upload_images_from_folder(
                self.folder_path,
                dataset_id=self.dataset_id,
                token=self.token
            )
Example #2
0
    def test_upload_images_metadata(self):
        self.setup(n_data=10)
        
        def get_tags_callback(request):
            return (200,[], json.dumps([]))
        
        def upload_sample_callback(request):
            return (200, [], json.dumps({'sampleId': 'x1y2'}))
        
        def put_dataset_callback(request):
            return (200,[], json.dumps([]))
        
        def post_tag_callback(request):
            return (200, [], json.dumps([]))

        def get_quota_callback(request):
            return (
                200,
                [],
                json.dumps({'maxDatasetSize': 25000})
            )

        responses.add_callback(
            responses.GET, self.gettag_url,
            callback=get_tags_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.POST, self.sample_url,
            callback=upload_sample_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.PUT, self.dataset_url,
            callback=put_dataset_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.POST, self.maketag_url,
            callback=post_tag_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET, self.getquota_url,
            callback=get_quota_callback,
            content_type='application/json'
        )

        api.upload_images_from_folder(
            self.folder_path,
            dataset_id=self.dataset_id,
            token=self.token,
            mode='metadata'
        )
Example #3
0
def _upload_cli(cfg, is_cli_call=True):

    input_dir = cfg['input_dir']
    if input_dir and is_cli_call:
        input_dir = fix_input_path(input_dir)

    path_to_embeddings = cfg['embeddings']
    if path_to_embeddings and is_cli_call:
        path_to_embeddings = fix_input_path(path_to_embeddings)

    dataset_id = cfg['dataset_id']
    token = cfg['token']

    size = cfg['resize']
    if not isinstance(size, int):
        size = tuple(size)

    if not token or not dataset_id:
        print('Please specify your access token and dataset id.')
        print('For help, try: lightly-upload --help')
        return

    if input_dir:
        mode = cfg['upload']
        try:
            upload_images_from_folder(input_dir,
                                      dataset_id,
                                      token,
                                      mode=mode,
                                      size=size)
        except (ValueError, ConnectionRefusedError) as error:
            msg = f'Error: {error}'
            print(msg)
            exit(0)

    if path_to_embeddings:
        max_upload = cfg['emb_upload_bsz']
        upload_embeddings_from_csv(path_to_embeddings,
                                   dataset_id,
                                   token,
                                   max_upload=max_upload,
                                   embedding_name=cfg['embedding_name'])
Example #4
0
    def test_upload_images_dataset_too_large(self):
        self.setup(n_data=25001)

        def get_quota_callback(request):
            return (
                200,
                [],
                json.dumps({'maxDatasetSize': 25000})
            )
        responses.add_callback(
            responses.GET, self.getquota_url,
            callback=get_quota_callback,
            content_type='application/json'
        )

        with self.assertRaises(ValueError):
            api.upload_images_from_folder(
                self.folder_path,
                dataset_id=self.dataset_id,
                token=self.token
            )
Example #5
0
    def test_upload_images_full(self):
        self.setup(n_data=10)
        
        def get_tags_callback(request):
            return (200,[], json.dumps([]))
        
        def upload_sample_callback(request):
            return (200, [], json.dumps({'sampleId': 'x1y2'}))
        
        def get_thumbnail_write_url_callback(request):
            return (200, [], json.dumps({'signedWriteUrl': self.signed_url}))
        
        def put_thumbnail_callback(request):
            return (200, [], json.dumps({}))
        
        def put_dataset_callback(request):
            return (200,[], json.dumps([]))
        
        def post_tag_callback(request):
            return (200, [], json.dumps([]))

        def get_quota_callback(request):
            return (
                200,
                [],
                json.dumps({'maxDatasetSize': 25000})
            )

        responses.add_callback(
            responses.GET, self.gettag_url,
            callback=get_tags_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.POST, self.sample_url,
            callback=upload_sample_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            f'{self.dst_url}/users/datasets/{self.dataset_id}/samples/x1y2/writeurl',
            callback=get_thumbnail_write_url_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.PUT, self.signed_url,
            callback=put_thumbnail_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.PUT, self.dataset_url,
            callback=put_dataset_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.POST, self.maketag_url,
            callback=post_tag_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET, self.getquota_url,
            callback=get_quota_callback,
            content_type='application/json'
        )

        api.upload_images_from_folder(
            self.folder_path,
            dataset_id=self.dataset_id,
            token=self.token,
            mode='full'
        )