Python object_detection.utils.learning_schedules.cosine_decay_with_warmup() Examples

The following are 30 code examples of object_detection.utils.learning_schedules.cosine_decay_with_warmup(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module object_detection.utils.learning_schedules , or try the search function .
Example #1
Source File: learning_schedules_test.py    From MAX-Object-Detector with Apache License 2.0 6 votes vote down vote up
def testCosineDecayAfterTotalSteps(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 100
      warmup_learning_rate = 0.1
      warmup_steps = 9
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps)
      assert learning_rate.op.name.endswith('learning_rate')
      return (learning_rate,)
    exp_rates = [0]
    input_global_steps = [101]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #2
Source File: learning_schedules_test.py    From BMW-TensorFlow-Training-GUI with Apache License 2.0 6 votes vote down vote up
def testCosineDecayWithWarmup(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 100
      warmup_learning_rate = 0.1
      warmup_steps = 9
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps)
      assert learning_rate.op.name.endswith('learning_rate')
      return (learning_rate,)
    exp_rates = [0.1, 0.5, 0.9, 1.0, 0]
    input_global_steps = [0, 4, 8, 9, 100]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #3
Source File: learning_schedules_test.py    From BMW-TensorFlow-Training-GUI with Apache License 2.0 6 votes vote down vote up
def testCosineDecayAfterTotalSteps(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 100
      warmup_learning_rate = 0.1
      warmup_steps = 9
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps)
      assert learning_rate.op.name.endswith('learning_rate')
      return (learning_rate,)
    exp_rates = [0]
    input_global_steps = [101]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #4
Source File: learning_schedules_test.py    From BMW-TensorFlow-Training-GUI with Apache License 2.0 6 votes vote down vote up
def testCosineDecayWithHoldBaseLearningRateSteps(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 120
      warmup_learning_rate = 0.1
      warmup_steps = 9
      hold_base_rate_steps = 20
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps, hold_base_rate_steps)
      assert learning_rate.op.name.endswith('learning_rate')
      return (learning_rate,)
    exp_rates = [0.1, 0.5, 0.9, 1.0, 1.0, 1.0, 0.999702, 0.874255, 0.577365,
                 0.0]
    input_global_steps = [0, 4, 8, 9, 10, 29, 30, 50, 70, 120]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #5
Source File: learning_schedules_test.py    From Live-feed-object-device-identification-using-Tensorflow-and-OpenCV with Apache License 2.0 6 votes vote down vote up
def testCosineDecayWithWarmup(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 100
      warmup_learning_rate = 0.1
      warmup_steps = 9
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps)
      assert learning_rate.op.name.endswith('learning_rate')
      return (learning_rate,)
    exp_rates = [0.1, 0.5, 0.9, 1.0, 0]
    input_global_steps = [0, 4, 8, 9, 100]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #6
Source File: learning_schedules_test.py    From Live-feed-object-device-identification-using-Tensorflow-and-OpenCV with Apache License 2.0 6 votes vote down vote up
def testCosineDecayAfterTotalSteps(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 100
      warmup_learning_rate = 0.1
      warmup_steps = 9
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps)
      assert learning_rate.op.name.endswith('learning_rate')
      return (learning_rate,)
    exp_rates = [0]
    input_global_steps = [101]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #7
Source File: learning_schedules_test.py    From Live-feed-object-device-identification-using-Tensorflow-and-OpenCV with Apache License 2.0 6 votes vote down vote up
def testCosineDecayWithHoldBaseLearningRateSteps(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 120
      warmup_learning_rate = 0.1
      warmup_steps = 9
      hold_base_rate_steps = 20
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps, hold_base_rate_steps)
      assert learning_rate.op.name.endswith('learning_rate')
      return (learning_rate,)
    exp_rates = [0.1, 0.5, 0.9, 1.0, 1.0, 1.0, 0.999702, 0.874255, 0.577365,
                 0.0]
    input_global_steps = [0, 4, 8, 9, 10, 29, 30, 50, 70, 120]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #8
Source File: learning_schedules_test.py    From Elphas with Apache License 2.0 6 votes vote down vote up
def testCosineDecayWithWarmup(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 100
      warmup_learning_rate = 0.1
      warmup_steps = 9
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps)
      return (learning_rate,)
    exp_rates = [0.1, 0.5, 0.9, 1.0, 0]
    input_global_steps = [0, 4, 8, 9, 100]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #9
Source File: learning_schedules_test.py    From object_detection_with_tensorflow with MIT License 6 votes vote down vote up
def testCosineDecayWithWarmup(self):
    global_step = tf.placeholder(tf.int32, [])
    learning_rate_base = 1.0
    total_steps = 100
    warmup_learning_rate = 0.1
    warmup_steps = 9
    input_global_steps = [0, 4, 8, 9, 100]
    exp_rates = [0.1, 0.5, 0.9, 1.0, 0]
    learning_rate = learning_schedules.cosine_decay_with_warmup(
        global_step, learning_rate_base, total_steps,
        warmup_learning_rate, warmup_steps)
    with self.test_session() as sess:
      output_rates = []
      for input_global_step in input_global_steps:
        output_rate = sess.run(learning_rate,
                               feed_dict={global_step: input_global_step})
        output_rates.append(output_rate)
      self.assertAllClose(output_rates, exp_rates) 
Example #10
Source File: learning_schedules_test.py    From object_detection_with_tensorflow with MIT License 6 votes vote down vote up
def testCosineDecayWithWarmup(self):
    global_step = tf.placeholder(tf.int32, [])
    learning_rate_base = 1.0
    total_steps = 100
    warmup_learning_rate = 0.1
    warmup_steps = 9
    input_global_steps = [0, 4, 8, 9, 100]
    exp_rates = [0.1, 0.5, 0.9, 1.0, 0]
    learning_rate = learning_schedules.cosine_decay_with_warmup(
        global_step, learning_rate_base, total_steps,
        warmup_learning_rate, warmup_steps)
    with self.test_session() as sess:
      output_rates = []
      for input_global_step in input_global_steps:
        output_rate = sess.run(learning_rate,
                               feed_dict={global_step: input_global_step})
        output_rates.append(output_rate)
      self.assertAllClose(output_rates, exp_rates) 
Example #11
Source File: learning_schedules_test.py    From AniSeg with Apache License 2.0 6 votes vote down vote up
def testCosineDecayWithWarmup(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 100
      warmup_learning_rate = 0.1
      warmup_steps = 9
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps)
      return (learning_rate,)
    exp_rates = [0.1, 0.5, 0.9, 1.0, 0]
    input_global_steps = [0, 4, 8, 9, 100]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #12
Source File: learning_schedules_test.py    From MAX-Object-Detector with Apache License 2.0 6 votes vote down vote up
def testCosineDecayWithWarmup(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 100
      warmup_learning_rate = 0.1
      warmup_steps = 9
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps)
      assert learning_rate.op.name.endswith('learning_rate')
      return (learning_rate,)
    exp_rates = [0.1, 0.5, 0.9, 1.0, 0]
    input_global_steps = [0, 4, 8, 9, 100]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #13
Source File: learning_schedules_test.py    From vehicle_counting_tensorflow with MIT License 6 votes vote down vote up
def testCosineDecayAfterTotalSteps(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 100
      warmup_learning_rate = 0.1
      warmup_steps = 9
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps)
      assert learning_rate.op.name.endswith('learning_rate')
      return (learning_rate,)
    exp_rates = [0]
    input_global_steps = [101]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #14
Source File: learning_schedules_test.py    From MAX-Object-Detector with Apache License 2.0 6 votes vote down vote up
def testCosineDecayWithHoldBaseLearningRateSteps(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 120
      warmup_learning_rate = 0.1
      warmup_steps = 9
      hold_base_rate_steps = 20
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps, hold_base_rate_steps)
      assert learning_rate.op.name.endswith('learning_rate')
      return (learning_rate,)
    exp_rates = [0.1, 0.5, 0.9, 1.0, 1.0, 1.0, 0.999702, 0.874255, 0.577365,
                 0.0]
    input_global_steps = [0, 4, 8, 9, 10, 29, 30, 50, 70, 120]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #15
Source File: learning_schedules_test.py    From g-tensorflow-models with Apache License 2.0 6 votes vote down vote up
def testCosineDecayWithWarmup(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 100
      warmup_learning_rate = 0.1
      warmup_steps = 9
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps)
      assert learning_rate.op.name.endswith('learning_rate')
      return (learning_rate,)
    exp_rates = [0.1, 0.5, 0.9, 1.0, 0]
    input_global_steps = [0, 4, 8, 9, 100]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #16
Source File: learning_schedules_test.py    From g-tensorflow-models with Apache License 2.0 6 votes vote down vote up
def testCosineDecayAfterTotalSteps(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 100
      warmup_learning_rate = 0.1
      warmup_steps = 9
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps)
      assert learning_rate.op.name.endswith('learning_rate')
      return (learning_rate,)
    exp_rates = [0]
    input_global_steps = [101]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #17
Source File: learning_schedules_test.py    From g-tensorflow-models with Apache License 2.0 6 votes vote down vote up
def testCosineDecayWithHoldBaseLearningRateSteps(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 120
      warmup_learning_rate = 0.1
      warmup_steps = 9
      hold_base_rate_steps = 20
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps, hold_base_rate_steps)
      assert learning_rate.op.name.endswith('learning_rate')
      return (learning_rate,)
    exp_rates = [0.1, 0.5, 0.9, 1.0, 1.0, 1.0, 0.999702, 0.874255, 0.577365,
                 0.0]
    input_global_steps = [0, 4, 8, 9, 10, 29, 30, 50, 70, 120]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #18
Source File: learning_schedules_test.py    From models with Apache License 2.0 6 votes vote down vote up
def testCosineDecayWithWarmup(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 100
      warmup_learning_rate = 0.1
      warmup_steps = 9
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps)
      assert learning_rate.op.name.endswith('learning_rate')
      return (learning_rate,)
    exp_rates = [0.1, 0.5, 0.9, 1.0, 0]
    input_global_steps = [0, 4, 8, 9, 100]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #19
Source File: learning_schedules_test.py    From models with Apache License 2.0 6 votes vote down vote up
def testCosineDecayAfterTotalSteps(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 100
      warmup_learning_rate = 0.1
      warmup_steps = 9
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps)
      assert learning_rate.op.name.endswith('learning_rate')
      return (learning_rate,)
    exp_rates = [0]
    input_global_steps = [101]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #20
Source File: learning_schedules_test.py    From models with Apache License 2.0 6 votes vote down vote up
def testCosineDecayWithHoldBaseLearningRateSteps(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 120
      warmup_learning_rate = 0.1
      warmup_steps = 9
      hold_base_rate_steps = 20
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps, hold_base_rate_steps)
      assert learning_rate.op.name.endswith('learning_rate')
      return (learning_rate,)
    exp_rates = [0.1, 0.5, 0.9, 1.0, 1.0, 1.0, 0.999702, 0.874255, 0.577365,
                 0.0]
    input_global_steps = [0, 4, 8, 9, 10, 29, 30, 50, 70, 120]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #21
Source File: learning_schedules_test.py    From multilabel-image-classification-tensorflow with MIT License 6 votes vote down vote up
def testCosineDecayWithWarmup(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 100
      warmup_learning_rate = 0.1
      warmup_steps = 9
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps)
      assert learning_rate.op.name.endswith('learning_rate')
      return (learning_rate,)
    exp_rates = [0.1, 0.5, 0.9, 1.0, 0]
    input_global_steps = [0, 4, 8, 9, 100]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #22
Source File: learning_schedules_test.py    From multilabel-image-classification-tensorflow with MIT License 6 votes vote down vote up
def testCosineDecayAfterTotalSteps(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 100
      warmup_learning_rate = 0.1
      warmup_steps = 9
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps)
      assert learning_rate.op.name.endswith('learning_rate')
      return (learning_rate,)
    exp_rates = [0]
    input_global_steps = [101]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #23
Source File: learning_schedules_test.py    From multilabel-image-classification-tensorflow with MIT License 6 votes vote down vote up
def testCosineDecayWithHoldBaseLearningRateSteps(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 120
      warmup_learning_rate = 0.1
      warmup_steps = 9
      hold_base_rate_steps = 20
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps, hold_base_rate_steps)
      assert learning_rate.op.name.endswith('learning_rate')
      return (learning_rate,)
    exp_rates = [0.1, 0.5, 0.9, 1.0, 1.0, 1.0, 0.999702, 0.874255, 0.577365,
                 0.0]
    input_global_steps = [0, 4, 8, 9, 10, 29, 30, 50, 70, 120]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #24
Source File: learning_schedules_test.py    From ros_tensorflow with Apache License 2.0 6 votes vote down vote up
def testCosineDecayWithHoldBaseLearningRateSteps(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 120
      warmup_learning_rate = 0.1
      warmup_steps = 9
      hold_base_rate_steps = 20
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps, hold_base_rate_steps)
      assert learning_rate.op.name.endswith('learning_rate')
      return (learning_rate,)
    exp_rates = [0.1, 0.5, 0.9, 1.0, 1.0, 1.0, 0.999702, 0.874255, 0.577365,
                 0.0]
    input_global_steps = [0, 4, 8, 9, 10, 29, 30, 50, 70, 120]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #25
Source File: learning_schedules_test.py    From Person-Detection-and-Tracking with MIT License 6 votes vote down vote up
def testCosineDecayAfterTotalSteps(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 100
      warmup_learning_rate = 0.1
      warmup_steps = 9
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps)
      assert learning_rate.op.name.endswith('learning_rate')
      return (learning_rate,)
    exp_rates = [0]
    input_global_steps = [101]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #26
Source File: learning_schedules_test.py    From Person-Detection-and-Tracking with MIT License 6 votes vote down vote up
def testCosineDecayWithHoldBaseLearningRateSteps(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 120
      warmup_learning_rate = 0.1
      warmup_steps = 9
      hold_base_rate_steps = 20
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps, hold_base_rate_steps)
      assert learning_rate.op.name.endswith('learning_rate')
      return (learning_rate,)
    exp_rates = [0.1, 0.5, 0.9, 1.0, 1.0, 1.0, 0.999702, 0.874255, 0.577365,
                 0.0]
    input_global_steps = [0, 4, 8, 9, 10, 29, 30, 50, 70, 120]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #27
Source File: learning_schedules_test.py    From Person-Detection-and-Tracking with MIT License 6 votes vote down vote up
def testCosineDecayWithWarmup(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 100
      warmup_learning_rate = 0.1
      warmup_steps = 9
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps)
      assert learning_rate.op.name.endswith('learning_rate')
      return (learning_rate,)
    exp_rates = [0.1, 0.5, 0.9, 1.0, 0]
    input_global_steps = [0, 4, 8, 9, 100]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #28
Source File: learning_schedules_test.py    From yolo_v2 with Apache License 2.0 6 votes vote down vote up
def testCosineDecayWithWarmup(self):
    global_step = tf.placeholder(tf.int32, [])
    learning_rate_base = 1.0
    total_steps = 100
    warmup_learning_rate = 0.1
    warmup_steps = 9
    input_global_steps = [0, 4, 8, 9, 100]
    exp_rates = [0.1, 0.5, 0.9, 1.0, 0]
    learning_rate = learning_schedules.cosine_decay_with_warmup(
        global_step, learning_rate_base, total_steps,
        warmup_learning_rate, warmup_steps)
    with self.test_session() as sess:
      output_rates = []
      for input_global_step in input_global_steps:
        output_rate = sess.run(learning_rate,
                               feed_dict={global_step: input_global_step})
        output_rates.append(output_rate)
      self.assertAllClose(output_rates, exp_rates) 
Example #29
Source File: learning_schedules_test.py    From ros_people_object_detection_tensorflow with Apache License 2.0 6 votes vote down vote up
def testCosineDecayWithHoldBaseLearningRateSteps(self):
    def graph_fn(global_step):
      learning_rate_base = 1.0
      total_steps = 120
      warmup_learning_rate = 0.1
      warmup_steps = 9
      hold_base_rate_steps = 20
      learning_rate = learning_schedules.cosine_decay_with_warmup(
          global_step, learning_rate_base, total_steps,
          warmup_learning_rate, warmup_steps, hold_base_rate_steps)
      assert learning_rate.op.name.endswith('learning_rate')
      return (learning_rate,)
    exp_rates = [0.1, 0.5, 0.9, 1.0, 1.0, 1.0, 0.999702, 0.874255, 0.577365,
                 0.0]
    input_global_steps = [0, 4, 8, 9, 10, 29, 30, 50, 70, 120]
    output_rates = [
        self.execute(graph_fn, [np.array(step).astype(np.int64)])
        for step in input_global_steps
    ]
    self.assertAllClose(output_rates, exp_rates) 
Example #30
Source File: learning_schedules_test.py    From Traffic-Rule-Violation-Detection-System with MIT License 6 votes vote down vote up
def testCosineDecayWithWarmup(self):
    global_step = tf.placeholder(tf.int32, [])
    learning_rate_base = 1.0
    total_steps = 100
    warmup_learning_rate = 0.1
    warmup_steps = 9
    input_global_steps = [0, 4, 8, 9, 100]
    exp_rates = [0.1, 0.5, 0.9, 1.0, 0]
    learning_rate = learning_schedules.cosine_decay_with_warmup(
        global_step, learning_rate_base, total_steps,
        warmup_learning_rate, warmup_steps)
    with self.test_session() as sess:
      output_rates = []
      for input_global_step in input_global_steps:
        output_rate = sess.run(learning_rate,
                               feed_dict={global_step: input_global_step})
        output_rates.append(output_rate)
      self.assertAllClose(output_rates, exp_rates)