summaryrefslogtreecommitdiff
path: root/cli/app/commands/bigbigan/fetch.py
blob: 5b6c102226a79f53413daf96f648e1276c14ba54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import click

from app.utils import click_utils
from app.settings import app_cfg

from os.path import join
from subprocess import call

@click.command('')
# @click.option('-i', '--input', 'opt_dir_in', required=True, 
#   help='Path to input image glob directory')
# @click.option('-r', '--recursive', 'opt_recursive', is_flag=True)
@click.pass_context
def cli(ctx):
  """
  """

  # app_cfg.MODELZOO_CFG
  import gensim
  
  # from nltk.corpus import wordnet as wn
  # synsets = wordnet.synsets("fir_tree")
  # synonyms = [ lemma.name() for lemma in synsets[0].lemmas() ]

  imagenet = Imagenet()

  sentence = "The quick brown fox jumps over the lazy dog"
  tokens = gensim.utils.simple_preprocess(sentence)

class Imagenet:
  def __init__():
    tokens = {}
    with open(app_cfg.FP_IMAGENET_WORDS, "r") as fp:
      for line in fp.readlines():
        wordnet_id, word_list = line.split('\t')
        words = [word.trim() for word in word_list.split(',')]
        for word in words:
          tokens[word] = wordnet_id
    self.tokens = tokens
 
  def get_wordnet_ids_for_words(tokens):
    # for token in tokens:
      # if token in tokens:
    pass

  def images_from_wordnet_id(wordnet_id):
    """
    Given a Wordnet ID, download images for this class
    """
    call([
      "python",
      join(app_cfg.DIR_APP, "../ImageNet-Datasets-Downloader/downloader.py"),
      '-data_root', app_cfg.FP_IMAGENET,
      '-use_class_list', 'True',
      '-class_list', wordnet_id,
      '-images_per_class', app_cfg.IMAGENET_IMAGES_PER_CLASS
    ])