This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, torch, datetime, gym | |
from torch.utils.tensorboard import SummaryWriter | |
class Actor(torch.nn.Module): | |
def __init__(self, state_size, action_size): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gym, torch, datetime, os | |
from torch.utils.tensorboard import SummaryWriter | |
env = gym.make('CartPole-v1') | |
class Actor(torch.nn.Module): | |
def __init__(self, state_size, action_size): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
acc_summary = sess.run(acc_summary_op, feed_dict={lazy_acc_score_ph: acc_score}) | |
writer.add_summary(acc_summary, global_step = step) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lazy_acc_score_ph = tf.placeholder(tf.float32, [1]) | |
lazy_acc_score_ts = tf.reduce_sum(lazy_acc_score_ph) | |
#... | |
# summary op for recording externally calculated metric(acc_score) | |
acc_summary_op = tf.summary.scalar("metric/acc", lazy_acc_score_ts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# calculate accuracy outside of the computational graph | |
pred_argmax = np.argmax(prediction, axis=1) | |
label_argmax = np.argmax(test_label, axis=1) | |
acc_score = accuracy_score(label_argmax, pred_argmax) | |
acc_score = np.reshape(acc_score,(1,)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for step in range(steps): | |
train_summary, loss_val, prediction, _ = sess.run([train_summary_op, loss_ts, prediction_ts, optimizer_op], | |
feed_dict={input_ph: train_input, onehot_labels_ph: train_label}) | |
writer.add_summary(train_summary, global_step = step) | |
print("train done for step={}".format(step)) | |
if step!=0 and step%5==0: | |
test_summary = sess.run(test_summary_op, feed_dict={input_ph: test_input, onehot_labels_ph: test_label}) | |
writer.add_summary(test_summary, global_step = step) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in training, we want to log loss value, accuracy value | |
loss_summary = tf.summary.scalar("loss/loss", loss_ts) | |
train_accuracy_summary = tf.summary.scalar("metric/acc", accuracy_ts) | |
# will detect loss_summary and train_accuracy_summary | |
train_summary_op = tf.summary.merge_all() | |
test_accuracy_summary = tf.summary.scalar("test/acc", accuracy_ts) | |
test_summary_op = tf.summary.merge([test_accuracy_summary]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from sklearn.metrics import accuracy_score | |
import tensorflow as tf | |
import tensorflow.contrib.slim.nets as nets | |
# tf version: 1.10.0 | |
def get_random_input_and_label(batch_size, class_size): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import tensorflow as tf | |
import tensorflow.contrib.slim.nets as nets | |
# tf version: 1.10.0 | |
def get_random_input_and_label(batch_size, class_size): | |
# for demonstration purpose, I'm going to reuse a random input and label |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def calc_prf_single(gt_box_list, pred_box_list): | |
""" | |
prf: precision/recall/f1-score | |
when matching, I did not consider conf value at the moment. This policy may change. | |
""" | |
gt_assign_map={} | |
# for gt_box in gt_box_list: |
NewerOlder