예제 #1
0
class LandmarkDataLayer(caffe.Layer):
    def setup(self, bottom, top):
        param = eval(self.param_str)
        self.batch = int(param['batch'])
        self.img_size = config.IMG_SIZE

        self.batch_loader = BatchLoader(param, "train")
        self.ohem_batch_loader = BatchLoader(param, 'ohem')
        self.train_ratio = 1.
        self.ohem_ratio = 0
        if self.ohem_batch_loader.is_loaded():
            self.train_ratio = 7 / 8.
            self.ohem_ratio = 1. - self.train_ratio
        top[0].reshape(self.batch, 3, self.img_size, self.img_size)  # data
        top[1].reshape(self.batch, config.LANDMARK_SIZE * 2)  # landmark
        top[2].reshape(self.batch, 1)  # landmark

    def reshape(self, bottom, top):
        pass

    def forward(self, bottom, top):
        batch_data = self.batch_loader.next_batch(
            self.batch * self.train_ratio, '')
        batch_data += self.ohem_batch_loader.next_batch(
            self.batch * self.ohem_ratio, '')
        for i, datum in enumerate(batch_data):
            img, pts, eye_dist = datum
            top[0].data[i, ...] = img
            top[1].data[i, ...] = pts
            top[2].data[i, ...] = eye_dist

    def backward(self, bottom, top):
        pass
예제 #2
0
class LandmarkDataLayer(caffe.Layer):
    def setup(self, bottom, top):
        param = eval(self.param_str)
        self.batch = int(param['batch'])

        self.batch_loader = BatchLoader(param, "train")
        self.ohem_batch_loader = BatchLoader(param, 'ohem')
        self.train_ratio = 1.
        self.ohem_ratio = 0
        if self.ohem_batch_loader.is_loaded():
            self.train_ratio = 7 / 8.
            self.ohem_ratio = 1. - self.train_ratio
        top[0].reshape(self.batch, 3, self.img_size, self.img_size)  # data
        top[1].reshape(self.batch, 72)  # landmark

    def reshape(self, bottom, top):
        pass

    def forward(self, bottom, top):
        batch_data = self.batch_loader.next_batch(
            self.batch * self.train_ratio, '')
        batch_data += self.ohem_batch_loader.next_batch(
            self.batch * self.ohem_ratio, '')
        random.shuffle(batch_data)
        for i, datum in enumerate(batch_data):
            img, label, bbox, landm5 = datum
            top[0].data[i, ...] = img
            top[1].data[i, ...] = label
            top[2].data[i, ...] = bbox
            if self.net != 'pnet':
                top[3].data[i, ...] = landm5

    def backward(self, bottom, top):
        pass
예제 #3
0
class DataLayer(caffe.Layer):
    def setup(self, bottom, top):
        param = eval(self.param_str)
        self.batch = int(param['batch'])
        self.net = param['net']
        self.img_size = config.NET_IMG_SIZES[self.net]

        self.batch_loader = BatchLoader(param, "train")
        self.ohem_batch_loader = BatchLoader(param, 'ohem')
        self.train_ratio = 1.
        self.ohem_ratio = 0
        if self.ohem_batch_loader.is_loaded():
            self.train_ratio = 7 / 8.
            self.ohem_ratio = 1 / 8.
        top[0].reshape(self.batch, 3, self.img_size, self.img_size)  # data
        top[1].reshape(self.batch, 1)  # label
        top[2].reshape(self.batch, 4)  # bbox
        if self.net != 'pnet':
            top[3].reshape(self.batch, config.LANDMARK_SIZE * 2)

    def reshape(self, bottom, top):
        pass

    def forward(self, bottom, top):
        task = random.choice(config.TRAIN_TASKS[self.net])
        batch_data = self.batch_loader.next_batch(
            self.batch * self.train_ratio, '')
        batch_data += self.ohem_batch_loader.next_batch(
            self.batch * self.ohem_ratio, '')
        random.shuffle(batch_data)
        for i, datum in enumerate(batch_data):
            img, label, bbox, landm5 = datum
            top[0].data[i, ...] = img
            top[1].data[i, ...] = label
            top[2].data[i, ...] = bbox
            if self.net != 'pnet':
                top[3].data[i, ...] = landm5

    def backward(self, bottom, top):
        pass