-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwrite_gspread.py
121 lines (81 loc) · 4.41 KB
/
write_gspread.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
# https://qiita.com/akabei/items/0eac37cb852ad476c6b9
import os
import glob
import gspread# https://qiita.com/akabei/items/0eac37cb852ad476c6b9
import os
import glob
import gspread
import pandas as pd
from oauth2client.service_account import ServiceAccountCredentials
global clear_last
clear_last = 1
#def update_gspread(dset_fname, train_acc, test_acc, train_loss, test_loss, epoch, otherparams):
def update_gspread(dset_fname, network_name, dataset_directory, train_acc, train_loss, test_acc, test_loss, current_epoch, all_epoch, otherparams=None):
global clear_last
### open google spreadsheet ###
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name('something.json', scope)
gc = gspread.authorize(credentials)
final_wks = gc.open('something').worksheet("Final")
last_wks = gc.open('something').worksheet("Last")
### updating ###
separate_dset_fname = dset_fname.split("_")
dataset_name = separate_dset_fname[0]
crp_x_length = separate_dset_fname[-8]
crp_y_length = separate_dset_fname[-7]
x_interval = separate_dset_fname[-6]
y_interval = separate_dset_fname[-5]
thorn = separate_dset_fname[-4]
num_of_class = len(os.listdir(dataset_directory + "/" + dset_fname + "/train/"))
resize_x_length = separate_dset_fname[-2]
resize_y_length = separate_dset_fname[-1]
train_list = glob.glob(dataset_directory + "/" + dset_fname + "/train/*/*.jpg", recursive=True)
test_list = glob.glob(dataset_directory + "/" + dset_fname + "/test/*/*.jpg", recursive=True)
new_row = [dataset_name, network_name, dataset_directory + "/" + dset_fname, train_loss, test_loss, train_acc, test_acc,
len(train_list)+len(test_list), len(train_list), len(test_list), num_of_class,
crp_x_length, crp_y_length, resize_x_length, resize_y_length, x_interval, y_interval, thorn, current_epoch]
for i in range(len(otherparams)):
new_row.append(otherparams[i])
if clear_last ==1:
last_wks.resize(3)
clear_last = 0
csvcolumns = ['dataset name', 'network name', 'place', 'train_loss', 'test_loss', 'train_acc', 'test_acc',
'total img', 'train img', 'test img', 'num of class', 'x-side', 'y-side', 'x-side', 'y-side', 'x-interval', 'y-interval', 'thorn', 'epoch']
for i in range(len(otherparams)):
csvcolumns.append('from nw')
df = pd.DataFrame(columns=csvcolumns)
df.to_csv('./' + dataset_name + '_' + network_name + '_result.csv')
last_wks.append_row(new_row)
df = pd.read_csv('./' + dataset_name + '_' + network_name + '_result.csv', index_col=0)
series = pd.Series(new_row, index=df.columns)
df = df.append(series, ignore_index=True)
df.to_csv('./' + dataset_name + '_' + network_name + '_result.csv')
if current_epoch == all_epoch-1:
final_wks.append_row(new_row)
from oauth2client.service_account import ServiceAccountCredentials
#def update_gspread(dset_fname, train_acc, test_acc, train_loss, test_loss, epoch, otherparams):
def update_gspread(dset_fname, network_name, dataset_directory, train_acc, train_loss, test_acc, test_loss, epoch, otherparams=None):
### open google spreadsheet ###
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name('something.json', scope)
gc = gspread.authorize(credentials)
wks = gc.open('something').sheet1
### updating ###
separate_dset_fname = dset_fname.split("_")
dataset_name = separate_dset_fname[0]
crp_x_length = separate_dset_fname[-8]
crp_y_length = separate_dset_fname[-7]
x_interval = separate_dset_fname[-6]
y_interval = separate_dset_fname[-5]
thorn = separate_dset_fname[-4]
num_of_class = len(os.listdir(dataset_directory + "/" + dset_fname + "/train/"))
resize_x_length = separate_dset_fname[-2]
resize_y_length = separate_dset_fname[-1]
train_list = glob.glob(dataset_directory + "/" + dset_fname + "/train/*/*.jpg", recursive=True)
test_list = glob.glob(dataset_directory + "/" + dset_fname + "/test/*/*.jpg", recursive=True)
new_row = [dataset_name, network_name, dataset_directory + "/" + dset_fname, train_loss, test_loss, train_acc, test_acc,
len(train_list)+len(test_list), len(train_list), len(test_list), num_of_class,
crp_x_length, crp_y_length, resize_x_length, resize_y_length, x_interval, y_interval, thorn, epoch]
for i in range(len(otherparams)):
new_row.append(otherparams[i])
wks.append_row(new_row)