MCPcopy Create free account
hub / github.com/JunlinHan/DCLGAN / GetData

Class GetData

util/get_data.py:11–110  ·  view source on GitHub ↗

A Python script for downloading CycleGAN or pix2pix datasets. Parameters: technique (str) -- One of: 'cyclegan' or 'pix2pix'. verbose (bool) -- If True, print additional information. Examples: >>> from util.get_data import GetData >>> gd = GetData(technique

Source from the content-addressed store, hash-verified

9
10
11class GetData(object):
12 """A Python script for downloading CycleGAN or pix2pix datasets.
13
14 Parameters:
15 technique (str) -- One of: 'cyclegan' or 'pix2pix'.
16 verbose (bool) -- If True, print additional information.
17
18 Examples:
19 >>> from util.get_data import GetData
20 >>> gd = GetData(technique='cyclegan')
21 >>> new_data_path = gd.get(save_path='./datasets') # options will be displayed.
22
23 Alternatively, You can use bash scripts: 'scripts/download_pix2pix_model.sh'
24 and 'scripts/download_cyclegan_model.sh'.
25 """
26
27 def __init__(self, technique='cyclegan', verbose=True):
28 url_dict = {
29 'pix2pix': 'http://efrosgans.eecs.berkeley.edu/pix2pix/datasets/',
30 'cyclegan': 'https://people.eecs.berkeley.edu/~taesung_park/CycleGAN/datasets'
31 }
32 self.url = url_dict.get(technique.lower())
33 self._verbose = verbose
34
35 def _print(self, text):
36 if self._verbose:
37 print(text)
38
39 @staticmethod
40 def _get_options(r):
41 soup = BeautifulSoup(r.text, 'lxml')
42 options = [h.text for h in soup.find_all('a', href=True)
43 if h.text.endswith(('.zip', 'tar.gz'))]
44 return options
45
46 def _present_options(self):
47 r = requests.get(self.url)
48 options = self._get_options(r)
49 print('Options:\n')
50 for i, o in enumerate(options):
51 print("{0}: {1}".format(i, o))
52 choice = input("\nPlease enter the number of the "
53 "dataset above you wish to download:")
54 return options[int(choice)]
55
56 def _download_data(self, dataset_url, save_path):
57 if not isdir(save_path):
58 os.makedirs(save_path)
59
60 base = basename(dataset_url)
61 temp_save_path = join(save_path, base)
62
63 with open(temp_save_path, "wb") as f:
64 r = requests.get(dataset_url)
65 f.write(r.content)
66
67 if base.endswith('.tar.gz'):
68 obj = tarfile.open(temp_save_path)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected