Example #1
0
    def test_upload_embeddings_with_tags(self):
        """Make sure upload of embeddings works.

        """

        self.setup(n_data=100)

        def get_tags_callback(request):
            return (200, [], json.dumps(['tag_1', 'tag_2']))

        def get_embs_callback(request):
            return (200, [], json.dumps([{'name': 'not_default'}]))

        def post_embedding_callback(request):
            return (200, [], json.dumps({}))

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

        responses.add_callback(
            responses.GET,
            f'{self.emb_url}/?token={self.token}&mode=summaries',
            callback=get_embs_callback,
            content_type='application/json')

        responses.add_callback(responses.POST,
                               self.emb_url,
                               callback=post_embedding_callback,
                               content_type='application/json')

        upload_embeddings_from_csv(self.path_to_embeddings,
                                   dataset_id=self.dataset_id,
                                   token=self.token)
Example #2
0
    def test_upload_embeddings_tag_exists(self):
        """

        """
        self.setup(n_data=10000)

        def get_tags_callback(request):
            return (200, [], json.dumps(['tag_1']))

        def get_embs_callback(request):
            return (200, [], json.dumps([{'name': 'default'}]))

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

        responses.add_callback(
            responses.GET,
            f'{self.emb_url}/?token={self.token}&mode=summaries',
            callback=get_embs_callback,
            content_type='application/json')

        with self.assertRaises(RuntimeError):
            success = upload_embeddings_from_csv(self.path_to_embeddings,
                                                 dataset_id=self.dataset_id,
                                                 token=self.token)
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_embeddings_no_tags(self):
        """Make sure upload of embeddings works.

        """

        self.setup(n_data=10000)

        def get_tags_callback(request):
            return (200, [], json.dumps([]))

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

        with self.assertRaises(RuntimeError):
            success = upload_embeddings_from_csv(self.path_to_embeddings,
                                                 dataset_id=self.dataset_id,
                                                 token=self.token)