Example #1
0
def auto_cropping(origin_image):
    batch_size = len(origin_image)

    terminals = np.zeros(batch_size)
    ratios = np.repeat([[0, 0, 20, 20]], batch_size, axis=0)
    img = crop_input(origin_image, generate_bbox(origin_image, ratios))

    global_feature = sess.run(global_feature_placeholder,
                              feed_dict={image_placeholder: img})
    h_np = np.zeros([batch_size, 1024])
    c_np = np.zeros([batch_size, 1024])

    while True:
        action_np, h_np, c_np = sess.run(
            (action, h, c),
            feed_dict={
                image_placeholder: img,
                global_feature_placeholder: global_feature,
                h_placeholder: h_np,
                c_placeholder: c_np
            })
        ratios, terminals = command2action(action_np, ratios, terminals)
        bbox = generate_bbox(origin_image, ratios)
        if np.sum(terminals) == batch_size:
            return bbox

        img = crop_input(origin_image, bbox)
Example #2
0
 def step(self, action, steps, last_score, ratios, dones):
     ratios, dones = command2action([action], ratios, dones)
     bbox = generate_bbox(np.expand_dims(self.origin_img, axis=0), ratios)
     # import pdb; pdb.set_trace();
     next_img = crop_input(np.expand_dims(self.origin_img, axis=0), bbox)
     cur_score, next_ob = self.score_feature(next_img[0])
     rew = 1 if cur_score>last_score else -1
     rew -= 0.001*(steps+1)
     rew -= 5 if (bbox[0][2] - bbox[0][0]) > 2*(bbox[0][3] - bbox[0][1]) \
             or (bbox[0][2] - bbox[0][0]) < 0.5*(bbox[0][3] - bbox[0][1]) else 0
     return next_ob, rew, cur_score, ratios, dones