我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用utils.Timer()。
def evaluate(sess): with Timer("get embedding for 1st half of evaluation data"): [senseVec, senseScore] = getEmbedding(sess,testData, testLocation) indices1 = range(0,len(senseVec),2) indices2 = range(1,len(senseVec),2) avgSimC = calAvgSimC(test_score, senseVec[indices1], senseScore[indices2], senseVec[indices2], senseScore[indices2]) maxSimC = calMaxSimC(test_score, senseVec[indices1], senseScore[indices2], senseVec[indices2], senseScore[indices2]) scores = [maxSimC, avgSimC] score_name = ['MaxSimC', 'AvgSimC'] print '============================' print 'AvgSimC =','{:.5f}'.format(avgSimC), 'MaxSimC =','{:.5f}'.format(maxSimC) print '============================' return [scores, score_name]
def evaluate(sess): with Timer("get embedding for 1st half of evaluation data"): [senseVec, senseScore] = getEmbedding(sess,testData, testLocation) indices1 = range(0,len(senseVec),2) indices2 = range(1,len(senseVec),2) avgSimC = calAvgSimC(test_score, senseVec[indices1], senseScore[indices2], senseVec[indices2], senseScore[indices2]) maxSimC = calMaxSimC(test_score, senseVec[indices1], senseScore[indices2], senseVec[indices2], senseScore[indices2]) scores = [maxSimC, avgSimC] score_name = ['MaxSimC', 'AvgSimC'] print 'AvgSimC =','{:.5f}'.format(avgSimC), 'MaxSimC =','{:.5f}'.format(maxSimC) return [scores, score_name]
def __init__(self): self.trajectory_topic = rospy.get_param("~trajectory_topic") self.odom_topic = rospy.get_param("~odom_topic") self.lookahead = rospy.get_param("~lookahead") self.max_reacquire = rospy.get_param("~max_reacquire") self.speed = float(rospy.get_param("~speed")) self.wrap = bool(rospy.get_param("~wrap")) wheelbase_length = float(rospy.get_param("~wheelbase")) self.drive_topic = rospy.get_param("~drive_topic") self.trajectory = utils.LineTrajectory("/followed_trajectory") self.model = utils.AckermannModel(wheelbase_length) self.do_viz = True self.odom_timer = utils.Timer(10) self.iters = 0 self.nearest_point = None self.lookahead_point = None # set up the visualization topic to show the nearest point on the trajectory, and the lookahead point self.viz_namespace = "/pure_pursuit" self.nearest_point_pub = rospy.Publisher(self.viz_namespace + "/nearest_point", Marker, queue_size = 1) self.lookahead_point_pub = rospy.Publisher(self.viz_namespace + "/lookahead_point", Marker, queue_size = 1) # topic to send drive commands to self.control_pub = rospy.Publisher(self.drive_topic, AckermannDriveStamped, queue_size =1 ) # topic to listen for trajectories self.traj_sub = rospy.Subscriber(self.trajectory_topic, PolygonStamped, self.trajectory_callback, queue_size=1) # topic to listen for odometry messages, either from particle filter or the simulator self.odom_sub = rospy.Subscriber(self.odom_topic, Odometry, self.odom_callback, queue_size=1) print "Initialized. Waiting on messages..."
def train(self): self.train_timer =Timer() self.losses_timer =Timer() self.tvd_timer =Timer() self.scatter_timer =Timer() self.log_step=50 self.max_step=50001 #self.max_step=501 for step in trange(self.max_step): if step % self.log_step == 0: for gan in self.gans: self.losses_timer.on() gan.record_losses(self.sess) self.losses_timer.off() self.tvd_timer.on() gan.record_tvd(self.sess) self.tvd_timer.off() if step % (10*self.log_step) == 0: for gan in self.gans: self.scatter_timer.on() gan.record_scatter(self.sess) #DEBUG: reassure me nothing changes during optimization #self.data_scatterplot() self.scatter_timer.off() if step % (5000) == 0: self.saver.save(self.sess,self.save_model_name,step) self.train_timer.on() self.sess.run(self.train_op) self.train_timer.off() print("Timers:") print(self.train_timer) print(self.losses_timer) print(self.tvd_timer) print(self.scatter_timer)