File size: 5,457 Bytes
6e601ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
"""
This script plots the result of the human evaluation on Amazon Mechanical Turk, where
human participants chose between an image from ClimateGAN or from a different method.
"""
print("Imports...", end="")
from argparse import ArgumentParser
import os
import yaml
import numpy as np
import pandas as pd
import seaborn as sns
from pathlib import Path
import matplotlib.pyplot as plt


# -----------------------
# -----  Constants  -----
# -----------------------

comparables_dict = {
    "munit_flooded": "MUNIT",
    "cyclegan": "CycleGAN",
    "instagan": "InstaGAN",
    "instagan_copypaste": "Mask-InstaGAN",
    "painted_ground": "Painted ground",
}


# Colors
palette_colorblind = sns.color_palette("colorblind")
color_climategan = palette_colorblind[9]

palette_colorblind = sns.color_palette("colorblind")
color_munit = palette_colorblind[1]
color_cyclegan = palette_colorblind[2]
color_instagan = palette_colorblind[3]
color_maskinstagan = palette_colorblind[6]
color_paintedground = palette_colorblind[8]
palette_comparables = [
    color_munit,
    color_cyclegan,
    color_instagan,
    color_maskinstagan,
    color_paintedground,
]
palette_comparables_light = [
    sns.light_palette(color, n_colors=3)[1] for color in palette_comparables
]


def parsed_args():
    """
    Parse and returns command-line args

    Returns:
        argparse.Namespace: the parsed arguments
    """
    parser = ArgumentParser()
    parser.add_argument(
        "--input_csv",
        default="amt_omni-vs-other.csv",
        type=str,
        help="CSV containing the results of the human evaluation, pre-processed",
    )
    parser.add_argument(
        "--output_dir",
        default=None,
        type=str,
        help="Output directory",
    )
    parser.add_argument(
        "--dpi",
        default=200,
        type=int,
        help="DPI for the output images",
    )
    parser.add_argument(
        "--n_bs",
        default=1e6,
        type=int,
        help="Number of bootrstrap samples",
    )
    parser.add_argument(
        "--bs_seed",
        default=17,
        type=int,
        help="Bootstrap random seed, for reproducibility",
    )

    return parser.parse_args()


if __name__ == "__main__":
    # -----------------------------
    # -----  Parse arguments  -----
    # -----------------------------
    args = parsed_args()
    print("Args:\n" + "\n".join([f"    {k:20}: {v}" for k, v in vars(args).items()]))

    # Determine output dir
    if args.output_dir is None:
        output_dir = Path(os.environ["SLURM_TMPDIR"])
    else:
        output_dir = Path(args.output_dir)
    if not output_dir.exists():
        output_dir.mkdir(parents=True, exist_ok=False)

    # Store args
    output_yml = output_dir / "args_human_evaluation.yml"
    with open(output_yml, "w") as f:
        yaml.dump(vars(args), f)

    # Read CSV
    df = pd.read_csv(args.input_csv)

    # Sort Y labels
    comparables = df.comparable.unique()
    is_climategan_sum = [
        df.loc[df.comparable == c, "climategan"].sum() for c in comparables
    ]
    comparables = comparables[np.argsort(is_climategan_sum)[::-1]]

    # Plot setup
    sns.set(style="whitegrid")
    plt.rcParams.update({"font.family": "serif"})
    plt.rcParams.update(
        {
            "font.serif": [
                "Computer Modern Roman",
                "Times New Roman",
                "Utopia",
                "New Century Schoolbook",
                "Century Schoolbook L",
                "ITC Bookman",
                "Bookman",
                "Times",
                "Palatino",
                "Charter",
                "serif" "Bitstream Vera Serif",
                "DejaVu Serif",
            ]
        }
    )
    fontsize = "medium"

    # Initialize the matplotlib figure
    fig, ax = plt.subplots(figsize=(10.5, 3), dpi=args.dpi)

    # Plot the total (right)
    sns.barplot(
        data=df.loc[df.is_valid],
        x="is_valid",
        y="comparable",
        order=comparables,
        orient="h",
        label="comparable",
        palette=palette_comparables_light,
        ci=None,
    )

    # Plot the left
    sns.barplot(
        data=df.loc[df.is_valid],
        x="climategan",
        y="comparable",
        order=comparables,
        orient="h",
        label="climategan",
        color=color_climategan,
        ci=99,
        n_boot=args.n_bs,
        seed=args.bs_seed,
        errcolor="black",
        errwidth=1.5,
        capsize=0.1,
    )

    # Draw line at 0.5
    y = np.arange(ax.get_ylim()[1] + 0.1, ax.get_ylim()[0], 0.1)
    x = 0.5 * np.ones(y.shape[0])
    ax.plot(x, y, linestyle=":", linewidth=1.5, color="black")

    # Change Y-Tick labels
    yticklabels = [comparables_dict[ytick.get_text()] for ytick in ax.get_yticklabels()]
    yticklabels_text = ax.set_yticklabels(
        yticklabels, fontsize=fontsize, horizontalalignment="right", x=0.96
    )
    for ytl in yticklabels_text:
        ax.add_artist(ytl)

    # Remove Y-label
    ax.set_ylabel(ylabel="")

    # Change X-Tick labels
    xlim = [0.0, 1.1]
    xticks = np.arange(xlim[0], xlim[1], 0.1)
    ax.set(xticks=xticks)
    plt.setp(ax.get_xticklabels(), fontsize=fontsize)

    # Set X-label
    ax.set_xlabel(None)

    # Change spines
    sns.despine(left=True, bottom=True)

    # Save figure
    output_fig = output_dir / "human_evaluation_rate_climategan.png"
    fig.savefig(output_fig, dpi=fig.dpi, bbox_inches="tight")