forked from hollobit/All-About-the-GAN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.py
179 lines (143 loc) · 6.06 KB
/
update.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# -*- coding: utf-8 -*-
""" Update Readme.md and cumulative_gans.jpg """
from __future__ import print_function
from __future__ import division
from wordcloud import WordCloud
from wordcloud import STOPWORDS
import numpy as np
import matplotlib.pyplot as plt
import sys
import datetime
import pandas as pd
import csv
import json
import os
def load_data():
""" Load GANs data from the AllGAN.csv file """
import csv
import codecs
with codecs.open('AllGAN-r2.tsv',"rbU", "utf-8") as fid:
reader = csv.DictReader(fid, delimiter='\t')
gans = [row for row in reader]
return gans
def update_readme(gans):
""" Update the Readme.md text file from a Jinja2 template """
import jinja2 as j2
gans.sort(key=lambda v: v['Title'].upper())
j2_env = j2.Environment(loader=j2.FileSystemLoader('.'),
trim_blocks=True, lstrip_blocks=True)
j2_env.globals['nowts'] = datetime.datetime.now()
with open('README-one.md', 'w') as fid:
print(j2_env.get_template('README.j2.md').render(gans=gans), file=fid)
def update_index(gans):
""" Update the index.html text file from a Jinja2 template """
import jinja2 as j2
try:
gans.sort(key=lambda v: ((int(v['Year']) if v['Year'].isdigit() else v['Year'])
, (int(v['Month']) if v['Month'].isdigit() else v['Month'])), reverse=True)
except:
pass
j2_env = j2.Environment(loader=j2.FileSystemLoader('.'),
trim_blocks=True, lstrip_blocks=True)
j2_env.globals['nowts'] = datetime.datetime.now()
with open('docs/index.html', 'w') as fid:
print(j2_env.get_template('INDEX.j2.md').render(gans=gans), file=fid)
def update_figure(gans):
""" Update the figure cumulative_gans.jpg """
data = np.array([int(gan['Year']) + int(gan['Month']) / 12
for gan in gans])
x_range = int(np.ceil(np.max(data) - np.min(data)) * 12) + 1
y_range = int(np.ceil(data.size / 10)) * 10 + 1
with plt.style.context("seaborn"):
plt.hist(data, x_range, cumulative="True")
plt.xticks(range(2014, 2018))
plt.yticks(np.arange(0, y_range, 15))
plt.title("Cumulative number of named GAN papers by month")
plt.xlabel("Year")
plt.ylabel("Total number of papers")
plt.savefig('cumulative_gans.jpg')
def update_wordcloud_title():
""" Update the figure wordcloud_title.jpg """
data = pd.read_csv('AllGAN-r2.tsv',delimiter='\t', encoding='utf-8')
# tmp_data = data['Title'].split(" ") for x in data
# count_list = list([list(x) for x in data['Title'].value_counts().reset_index().values])
# wordcloud = WordCloud(stopwords=STOPWORDS,relative_scaling = 0.2,
# max_words=2000, background_color='white').generate_from_frequencies(tmp_data)
stopwords = set(STOPWORDS)
#ganstop = ['Generative','Adversarial', 'Networks', 'Network', 'GAN', 'GANs', 'using', 'Learning', 'Training', 'Generation',
# 'Neural', 'Net', 'Model', 'Nets', 'Deep', 'Based', 'Via', 'Conditional', 'Models', 'Examples']
#stopwords.add(ganstop)
stopwords.add('Generative')
stopwords.add('Adversarial')
stopwords.add('Networks')
stopwords.add('Network')
stopwords.add('GAN')
stopwords.add('GANs')
stopwords.add('using')
stopwords.add('Learning')
stopwords.add('Training')
stopwords.add('Generation')
stopwords.add('Neural')
stopwords.add('Net')
stopwords.add('Model')
stopwords.add('Nets')
stopwords.add('Deep')
stopwords.add('Based')
stopwords.add('Via')
stopwords.add('Conditional')
stopwords.add('Models')
stopwords.add('Examples')
wordcloud = WordCloud(stopwords=stopwords,relative_scaling = 0.2, random_state=3,
max_words=2000, background_color='white').generate(' '.join(data['Title']))
plt.figure(figsize=(12,12))
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
#plt.show()
#plt.savefig('wordcloud_title.png')
wordcloud.to_file('wordcloud_title.png')
wordcloud.to_file('docs/png/wordcloud_title.png')
def update_wordcloud_category():
""" Update the figure wordcloud_category.jpg """
data = pd.read_csv('AllGAN-r2.tsv',delimiter='\t', encoding='utf-8')
wordcloud = WordCloud(stopwords=STOPWORDS,relative_scaling = 0.2, random_state=3,
max_words=2000, background_color='white').generate(' '.join(data['Category']))
plt.figure(figsize=(12,12))
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
#plt.show()
#plt.savefig('wordcloud_title.png')
wordcloud.to_file('wordcloud_category.png')
wordcloud.to_file('docs/png/wordcloud_category.png')
def update_wordcloud_abbr():
""" Update the figure wordcloud_category.jpg """
data = pd.read_csv('AllGAN-r2.tsv',delimiter='\t', encoding='utf-8')
wordcloud = WordCloud(stopwords=STOPWORDS,relative_scaling = 0.2, random_state=3,
max_words=2000, background_color='white').generate(' '.join(data['Abbr.']))
plt.figure(figsize=(12,12))
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
#plt.show()
#plt.savefig('wordcloud_title.png')
wordcloud.to_file('wordcloud_abbr.png')
wordcloud.to_file('docs/png/wordcloud_abbr.png')
def update_csv2json():
# COLUMNS = ('Mnum','Abbr.','Title','Year','Month','Citations','pdf','Arxiv','Official_Code','Tensorflow','PyTorch','KERAS', 'Stars','Web','No','SN','Medical','Category')
with open('AllGan-r2.tsv', 'r') as f:
reader = csv.DictReader(f, delimiter='\t')
rows = list(reader)
with open('docs/AllGan.json', 'w') as f:
f.write(json.dumps(rows, sort_keys=False, separators=(',', ': '), ensure_ascii=False, indent=4))
if __name__ == '__main__':
try:
reload(sys) # Python 2
sys.setdefaultencoding('utf-8')
except NameError:
pass # Python 3
GANS = load_data()
update_wordcloud_title()
update_wordcloud_category()
update_wordcloud_abbr()
update_readme(GANS)
update_index(GANS)
update_csv2json()
# update_figure(GANS)