예제 #1
0
 def __init__(self, lr=0.01, epsilon=1e-8, decay=0., **kwargs):
   super(Adagrad, self).__init__(**kwargs)
   self.lr = K.variable(lr, name='lr')
   self.epsilon = epsilon
   self.decay = K.variable(decay, name='decay')
   self.initial_decay = decay
   self.iterations = K.variable(0., name='iterations')
예제 #2
0
 def __init__(self, lr=0.01, epsilon=1e-8, decay=0., **kwargs):
     super(Adagrad, self).__init__(**kwargs)
     self.lr = K.variable(lr, name='lr')
     self.epsilon = epsilon
     self.decay = K.variable(decay, name='decay')
     self.initial_decay = decay
     self.iterations = K.variable(0., name='iterations')
예제 #3
0
 def __init__(self, lr=1.0, rho=0.95, epsilon=1e-8, decay=0., **kwargs):
   super(Adadelta, self).__init__(**kwargs)
   self.lr = K.variable(lr, name='lr')
   self.rho = rho
   self.epsilon = epsilon
   self.decay = K.variable(decay, name='decay')
   self.initial_decay = decay
   self.iterations = K.variable(0., name='iterations')
예제 #4
0
 def __init__(self, lr=0.001, rho=0.9, epsilon=1e-8, decay=0., **kwargs):
   super(RMSprop, self).__init__(**kwargs)
   self.lr = K.variable(lr, name='lr')
   self.rho = K.variable(rho, name='rho')
   self.epsilon = epsilon
   self.decay = K.variable(decay, name='decay')
   self.initial_decay = decay
   self.iterations = K.variable(0., name='iterations')
예제 #5
0
 def __init__(self, lr=0.01, momentum=0., decay=0., nesterov=False, **kwargs):
   super(SGD, self).__init__(**kwargs)
   self.iterations = K.variable(0., name='iterations')
   self.lr = K.variable(lr, name='lr')
   self.momentum = K.variable(momentum, name='momentum')
   self.decay = K.variable(decay, name='decay')
   self.initial_decay = decay
   self.nesterov = nesterov
예제 #6
0
 def __init__(self, lr=0.01, momentum=0., decay=0., nesterov=False, **kwargs):
   super(SGD, self).__init__(**kwargs)
   self.iterations = K.variable(0., name='iterations')
   self.lr = K.variable(lr, name='lr')
   self.momentum = K.variable(momentum, name='momentum')
   self.decay = K.variable(decay, name='decay')
   self.initial_decay = decay
   self.nesterov = nesterov
예제 #7
0
 def __init__(self, lr=1.0, rho=0.95, epsilon=1e-8, decay=0., **kwargs):
     super(Adadelta, self).__init__(**kwargs)
     self.lr = K.variable(lr, name='lr')
     self.rho = rho
     self.epsilon = epsilon
     self.decay = K.variable(decay, name='decay')
     self.initial_decay = decay
     self.iterations = K.variable(0., name='iterations')
예제 #8
0
 def __init__(self, lr=0.01, epsilon=1e-8, decay=0., **kwargs):
   super(Adagrad, self).__init__(**kwargs)
   with K.name_scope(self.__class__.__name__):
     self.lr = K.variable(lr, name='lr')
     self.decay = K.variable(decay, name='decay')
     self.iterations = K.variable(0, dtype='int64', name='iterations')
   self.epsilon = epsilon
   self.initial_decay = decay
예제 #9
0
 def __init__(self, lr=0.001, rho=0.9, epsilon=1e-8, decay=0., **kwargs):
     super(RMSprop, self).__init__(**kwargs)
     self.lr = K.variable(lr, name='lr')
     self.rho = K.variable(rho, name='rho')
     self.epsilon = epsilon
     self.decay = K.variable(decay, name='decay')
     self.initial_decay = decay
     self.iterations = K.variable(0., name='iterations')
예제 #10
0
 def __init__(self, lr=0.01, momentum=0., decay=0., nesterov=False, **kwargs):
   super(SGD, self).__init__(**kwargs)
   with K.name_scope(self.__class__.__name__):
     self.iterations = K.variable(0, dtype='int64', name='iterations')
     self.lr = K.variable(lr, name='lr')
     self.momentum = K.variable(momentum, name='momentum')
     self.decay = K.variable(decay, name='decay')
   self.initial_decay = decay
   self.nesterov = nesterov
예제 #11
0
 def __init__(self,
              lr=0.002,
              beta_1=0.9,
              beta_2=0.999,
              epsilon=1e-8,
              schedule_decay=0.004,
              **kwargs):
   super(Nadam, self).__init__(**kwargs)
   self.iterations = K.variable(0., name='iterations')
   self.m_schedule = K.variable(1., name='m_schedule')
   self.lr = K.variable(lr, name='lr')
   self.beta_1 = K.variable(beta_1, name='beta_1')
   self.beta_2 = K.variable(beta_2, name='beta_2')
   self.epsilon = epsilon
   self.schedule_decay = schedule_decay
예제 #12
0
 def __init__(self,
              lr=0.002,
              beta_1=0.9,
              beta_2=0.999,
              epsilon=1e-8,
              decay=0.,
              **kwargs):
   super(Adamax, self).__init__(**kwargs)
   self.iterations = K.variable(0., name='iterations')
   self.lr = K.variable(lr, name='lr')
   self.beta_1 = K.variable(beta_1, name='beta_1')
   self.beta_2 = K.variable(beta_2, name='beta_2')
   self.epsilon = epsilon
   self.decay = K.variable(decay, name='decay')
   self.initial_decay = decay
예제 #13
0
 def __init__(self,
              lr=0.002,
              beta_1=0.9,
              beta_2=0.999,
              epsilon=1e-8,
              decay=0.,
              **kwargs):
     super(Adamax, self).__init__(**kwargs)
     self.iterations = K.variable(0., name='iterations')
     self.lr = K.variable(lr, name='lr')
     self.beta_1 = K.variable(beta_1, name='beta_1')
     self.beta_2 = K.variable(beta_2, name='beta_2')
     self.epsilon = epsilon
     self.decay = K.variable(decay, name='decay')
     self.initial_decay = decay
예제 #14
0
 def __init__(self,
              lr=0.002,
              beta_1=0.9,
              beta_2=0.999,
              epsilon=1e-8,
              schedule_decay=0.004,
              **kwargs):
     super(Nadam, self).__init__(**kwargs)
     self.iterations = K.variable(0., name='iterations')
     self.m_schedule = K.variable(1., name='m_schedule')
     self.lr = K.variable(lr, name='lr')
     self.beta_1 = K.variable(beta_1, name='beta_1')
     self.beta_2 = K.variable(beta_2, name='beta_2')
     self.epsilon = epsilon
     self.schedule_decay = schedule_decay
예제 #15
0
def yolo_eval(yolo_outputs,
              image_shape,
              max_boxes=10,
              score_threshold=.6,
              iou_threshold=.5):
    """Evaluate YOLO model on given input batch and return filtered boxes."""
    box_xy, box_wh, box_confidence, box_class_probs = yolo_outputs
    boxes = yolo_boxes_to_corners(box_xy, box_wh)
    boxes, scores, classes = yolo_filter_boxes(boxes,
                                               box_confidence,
                                               box_class_probs,
                                               threshold=score_threshold)

    # Scale boxes back to original image shape.
    height = image_shape[0]
    width = image_shape[1]
    image_dims = K.stack([height, width, height, width])
    image_dims = K.reshape(image_dims, [1, 4])
    boxes = boxes * image_dims

    # TODO: Something must be done about this ugly hack!
    max_boxes_tensor = K.variable(max_boxes, dtype='int32')
    K.get_session().run(tf.variables_initializer([max_boxes_tensor]))
    nms_index = tf.image.non_max_suppression(boxes,
                                             scores,
                                             max_boxes_tensor,
                                             iou_threshold=iou_threshold)
    boxes = K.gather(boxes, nms_index)
    scores = K.gather(scores, nms_index)
    classes = K.gather(classes, nms_index)
    return boxes, scores, classes
예제 #16
0
 def __init__(self,
              lr=0.002,
              beta_1=0.9,
              beta_2=0.999,
              epsilon=1e-8,
              schedule_decay=0.004,
              **kwargs):
   super(Nadam, self).__init__(**kwargs)
   with K.name_scope(self.__class__.__name__):
     self.iterations = K.variable(0, dtype='int64', name='iterations')
     self.m_schedule = K.variable(1., name='m_schedule')
     self.lr = K.variable(lr, name='lr')
     self.beta_1 = K.variable(beta_1, name='beta_1')
     self.beta_2 = K.variable(beta_2, name='beta_2')
   self.epsilon = epsilon
   self.schedule_decay = schedule_decay
예제 #17
0
 def __init__(self,
              lr=0.002,
              beta_1=0.9,
              beta_2=0.999,
              epsilon=1e-8,
              decay=0.,
              **kwargs):
   super(Adamax, self).__init__(**kwargs)
   with K.name_scope(self.__class__.__name__):
     self.iterations = K.variable(0, dtype='int64', name='iterations')
     self.lr = K.variable(lr, name='lr')
     self.beta_1 = K.variable(beta_1, name='beta_1')
     self.beta_2 = K.variable(beta_2, name='beta_2')
     self.decay = K.variable(decay, name='decay')
   self.epsilon = epsilon
   self.initial_decay = decay
예제 #18
0
 def call(self, x, mask=None):
     input_shape = K.int_shape(x)
     layer_width = input_shape[self.waxis]
     layer_height = input_shape[self.haxis]
     img_width = self.img_size[0]
     img_height = self.img_size[1]
     # define prior boxes shapes
     box_widths = []
     box_heights = []
     for ar in self.aspect_ratios:
         if ar == 1 and len(box_widths) == 0:
             box_widths.append(self.min_size)
             box_heights.append(self.min_size)
         elif ar == 1 and len(box_widths) > 0:
             box_widths.append(np.sqrt(self.min_size * self.max_size))
             box_heights.append(np.sqrt(self.min_size * self.max_size))
         elif ar != 1:
             box_widths.append(self.min_size * np.sqrt(ar))
             box_heights.append(self.min_size / np.sqrt(ar))
     box_widths = 0.5 * np.array(box_widths)
     box_heights = 0.5 * np.array(box_heights)
     # define centers of prior boxes
     step_x = img_width / layer_width
     step_y = img_height / layer_height
     linx = np.linspace(0.5 * step_x, img_width - 0.5 * step_x, layer_width)
     liny = np.linspace(0.5 * step_y, img_height - 0.5 * step_y,
                        layer_height)
     centers_x, centers_y = np.meshgrid(linx, liny)
     centers_x = centers_x.reshape(-1, 1)
     centers_y = centers_y.reshape(-1, 1)
     # define xmin, ymin, xmax, ymax of prior boxes
     num_priors_ = len(self.aspect_ratios)
     prior_boxes = np.concatenate((centers_x, centers_y), axis=1)
     prior_boxes = np.tile(prior_boxes, (1, 2 * num_priors_))
     prior_boxes[:, ::4] -= box_widths
     prior_boxes[:, 1::4] -= box_heights
     prior_boxes[:, 2::4] += box_widths
     prior_boxes[:, 3::4] += box_heights
     prior_boxes[:, ::2] /= img_width
     prior_boxes[:, 1::2] /= img_height
     prior_boxes = prior_boxes.reshape(-1, 4)
     if self.clip:
         prior_boxes = np.minimum(np.maximum(prior_boxes, 0.0), 1.0)
     # define variances
     num_boxes = len(prior_boxes)
     if len(self.variances) == 1:
         variances = np.ones((num_boxes, 4)) * self.variances[0]
     elif len(self.variances) == 4:
         variances = np.tile(self.variances, (num_boxes, 1))
     else:
         raise Exception('Must provide one or four variances.')
     prior_boxes = np.concatenate((prior_boxes, variances), axis=1)
     prior_boxes_tensor = K.expand_dims(K.variable(prior_boxes), 0)
     pattern = [tf.shape(x)[0], 1, 1]
     prior_boxes_tensor = tf.tile(prior_boxes_tensor, pattern)
     return prior_boxes_tensor
예제 #19
0
 def __init__(self, optimizer):  # pylint: disable=super-init-not-called
     self.optimizer = optimizer
     self.iterations = K.variable(0., name='iterations')
     self.updates = []
예제 #20
0
 def build(self, input_shape):
     self.input_spec = [InputSpec(shape=input_shape)]
     shape = (input_shape[self.axis], )
     init_gamma = self.scale * np.ones(shape)
     self.gamma = K.variable(init_gamma, name='{}_gamma'.format(self.name))
     self.trainable_weights = [self.gamma]
예제 #21
0
 def __init__(self, optimizer):  # pylint: disable=super-init-not-called
   self.optimizer = optimizer
   self.iterations = K.variable(0., name='iterations')
   self.updates = []
예제 #22
0
 def __init__(self, optimizer):  # pylint: disable=super-init-not-called
   self.optimizer = optimizer
   with K.name_scope(self.__class__.__name__):
     self.iterations = K.variable(0, dtype='int64', name='iterations')