2015-09-24 07:51:47 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
2016-01-14 03:52:52 +08:00
|
|
|
# Copyright 2015-2016 Carnegie Mellon University
|
2015-09-24 07:51:47 +08:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
import matplotlib as mpl
|
|
|
|
mpl.use('Agg')
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
plt.style.use('bmh')
|
|
|
|
import pandas as pd
|
|
|
|
|
|
|
|
import os
|
2016-03-07 08:56:12 +08:00
|
|
|
import sys
|
2015-09-24 07:51:47 +08:00
|
|
|
|
|
|
|
scriptDir = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
plotDir = os.path.join(scriptDir, 'plots')
|
2016-06-14 01:49:24 +08:00
|
|
|
# workDir = os.path.join(scriptDir, 'work')
|
2015-09-24 07:51:47 +08:00
|
|
|
|
2015-10-12 23:30:29 +08:00
|
|
|
|
2015-09-24 07:51:47 +08:00
|
|
|
def plot(workDirs):
|
|
|
|
trainDfs = []
|
2016-03-07 08:46:33 +08:00
|
|
|
testDfs = []
|
2015-09-24 07:51:47 +08:00
|
|
|
for d in workDirs:
|
2016-06-14 01:49:24 +08:00
|
|
|
trainF = os.path.join(d, 'train.log')
|
|
|
|
testF = os.path.join(d, 'test.log')
|
2015-09-24 07:51:47 +08:00
|
|
|
trainDfs.append(pd.read_csv(trainF, sep='\t'))
|
2016-03-07 08:46:33 +08:00
|
|
|
testDfs.append(pd.read_csv(testF, sep='\t'))
|
|
|
|
if len(trainDfs[-1]) != len(testDfs[-1]):
|
|
|
|
print("Error: Train/test dataframe shapes "
|
|
|
|
"for '{}' don't match: {}, {}".format(
|
|
|
|
d, trainDfs[-1].shape, testDfs[-1].shape))
|
|
|
|
sys.exit(-1)
|
2015-09-24 07:51:47 +08:00
|
|
|
trainDf = pd.concat(trainDfs, ignore_index=True)
|
2016-03-07 08:46:33 +08:00
|
|
|
testDf = pd.concat(testDfs, ignore_index=True)
|
2015-09-24 07:51:47 +08:00
|
|
|
|
2016-01-07 05:04:10 +08:00
|
|
|
# print("train, test:")
|
|
|
|
# print("\n".join(["{:0.2e}, {:0.2e}".format(x, y) for (x, y) in
|
|
|
|
# zip(trainDf['avg triplet loss (train set)'].values[-5:],
|
|
|
|
# testDf['avg triplet loss (test set)'].values[-5:])]))
|
2015-09-24 07:51:47 +08:00
|
|
|
|
2015-10-12 23:30:29 +08:00
|
|
|
fig, ax = plt.subplots(1, 1)
|
2015-09-24 07:51:47 +08:00
|
|
|
trainDf.index += 1
|
2016-03-07 08:46:33 +08:00
|
|
|
trainDf['avg triplet loss (train set)'].plot(ax=ax)
|
2015-09-24 07:51:47 +08:00
|
|
|
plt.xlabel("Epoch")
|
2016-03-07 08:46:33 +08:00
|
|
|
plt.ylabel("Average Triplet Loss, Training")
|
2016-03-09 07:36:58 +08:00
|
|
|
plt.ylim(ymin=0)
|
2016-03-09 09:39:03 +08:00
|
|
|
# plt.xlim(xmin=1)
|
2015-09-24 07:51:47 +08:00
|
|
|
plt.grid(b=True, which='major', color='k', linestyle='-')
|
2016-03-19 02:10:53 +08:00
|
|
|
plt.grid(b=True, which='minor', color='k', linestyle='-', alpha=0.2)
|
|
|
|
plt.minorticks_on()
|
2016-03-09 07:36:58 +08:00
|
|
|
# ax.set_yscale('log')
|
2016-03-07 08:46:33 +08:00
|
|
|
d = os.path.join(plotDir, "train-loss.pdf")
|
|
|
|
fig.savefig(d)
|
|
|
|
print("Created {}".format(d))
|
|
|
|
|
|
|
|
fig, ax = plt.subplots(1, 1)
|
|
|
|
testDf.index += 1
|
|
|
|
testDf['lfwAcc'].plot(ax=ax)
|
|
|
|
plt.xlabel("Epoch")
|
|
|
|
plt.ylabel("LFW Accuracy")
|
|
|
|
plt.ylim(ymin=0, ymax=1)
|
2016-03-19 02:10:53 +08:00
|
|
|
plt.grid(b=True, which='major', color='k', linestyle='-')
|
|
|
|
plt.grid(b=True, which='minor', color='k', linestyle='-', alpha=0.2)
|
|
|
|
plt.minorticks_on()
|
2016-03-07 08:46:33 +08:00
|
|
|
# plt.xlim(xmin=1)
|
|
|
|
# ax.set_yscale('log')
|
|
|
|
d = os.path.join(plotDir, "lfw-accuracy.pdf")
|
|
|
|
fig.savefig(d)
|
|
|
|
print("Created {}".format(d))
|
2015-09-24 07:51:47 +08:00
|
|
|
|
2015-10-12 23:30:29 +08:00
|
|
|
if __name__ == '__main__':
|
2015-09-24 07:51:47 +08:00
|
|
|
os.makedirs(plotDir, exist_ok=True)
|
|
|
|
parser = argparse.ArgumentParser()
|
2016-06-14 01:49:24 +08:00
|
|
|
parser.add_argument('workDirs', type=str, nargs='+')
|
2015-09-24 07:51:47 +08:00
|
|
|
args = parser.parse_args()
|
|
|
|
plot(args.workDirs)
|