Skip to content

Commit

Permalink
finish train.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhimaoLin committed Apr 13, 2022
1 parent 291f375 commit e76dd98
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions MainPaper/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from util import *
import matplotlib.pyplot as plt

import time


DATA_SUMMARY_CSV_PATH = '../data_summary.csv'
DATA_SUMMARY_HEADER = {"person":"person_name", "video":"video_name", "frame":"frame_number", "pspi":"pspi_score", "image":"image_path"}
Expand Down Expand Up @@ -49,12 +51,12 @@ def print_opts(opts):
'image_scale_to_before_crop': 320,
'image_size': 160,
'number_output': 1,
'image_sample_size': 1,
'batch_size': 100,
'image_sample_size': 5,
'batch_size': 50,
'drop_out': 0,
'fc2_size': 200,
'learning_rate': 0.001,
'epoch': 1
'epoch': 10
}
ARGS.update(args_dict)
#endregion
Expand Down Expand Up @@ -153,7 +155,7 @@ def train(train_data_path, ops):
title = f"Epoch={epoch}, Train loss of each batch"
x_label = "Batch number"
y_label = "Loss"
save_path = os.path.join("./result", f"Epoch_{epoch}_loss.png")
save_path = os.path.join("./result", f"Epoch_{epoch+1}_loss.png")
draw_line_chart(x_list, train_loss_for_each_batch_list, title, x_label, y_label, save_path)

avg_loss_for_each_epoch = np.array(train_loss_for_each_batch_list).mean()
Expand All @@ -172,7 +174,10 @@ def train(train_data_path, ops):



def evaluation(net, test_data_loader):
def evaluation(net, test_data_path, ops):
test_dataset = MyDataset(test_data_path, ops)
test_data_loader = torch.utils.data.DataLoader(test_dataset, batch_size=ops.batch_size, shuffle=True)

mse_loss = nn.MSELoss()

total_number_batch = 0
Expand Down Expand Up @@ -204,8 +209,13 @@ def main():
create_data_csv(DATA_CSV_PATH, DATA_SUMMARY_CSV_PATH, ARGS)
split_dataset(DATA_CSV_PATH, TRAIN_DATA_CSV_PATH, TEST_DATA_CSV_PATH, RANDOM_SEED, TRAIN_FRACTION)

start = time.time()
net = train(TRAIN_DATA_CSV_PATH, ARGS)
evaluation(net, TEST_DATA_CSV_PATH)
end = time.time()
print(f"Runtime of the program is {end - start}")


evaluation(net, TEST_DATA_CSV_PATH, ARGS)



Expand Down

0 comments on commit e76dd98

Please sign in to comment.