Exemple #1
0
def _mask_dataset():
    # Load model and compile function
    with open('../cache/foreground_model.pkl', 'rb') as f:
        model, threshold = cPickle.load(f)

    x = T.matrix('x')
    y = model.get_output(x)
    output_func = theano.function(inputs=[x], outputs=(y >= threshold))

    # Load data
    image_data = DataLoader('../data/cuhk_small.mat', verbose=True)

    # Pre-processing
    print "Pre-processing ..."

    images = image_data.get_all_images()
    images = [_input_preproc(image) for image in images]
    images = imageproc.images2mat(images).astype(theano.config.floatX)

    # Compute masks
    print "Computing masks ..."

    masks = output_func(images)

    # Save masks
    print "Saving data ..."

    mask_data = DataSaver()

    cur_index = 0
    for gid in xrange(image_data.get_n_groups()):
        m, v = image_data.get_n_pedes_views(gid)
        mask_data.add_group(m, v)

        for pid in xrange(m):
            n_images = image_data.get_n_images(gid, pid)

            for vid, n in enumerate(n_images):
                view_masks = [0] * n
                for k in xrange(n):
                    mask = masks[cur_index, :]
                    mask = mask.reshape(160, 80, 1)
                    orig_image = image_data.get_image(gid, pid, vid, k)
                    orig_image = imageproc.imresize(orig_image, (160, 80, 3))
                    view_masks[k] = (mask * orig_image).astype(numpy.uint8)
                    cur_index += 1

                mask_data.set_images(gid, pid, vid, view_masks)

    mask_data.save('../data/cuhk_small_masked.mat')
def _mask_dataset():
    # Load model and compile function
    with open('../cache/foreground_model.pkl', 'rb') as f:
        model, threshold = cPickle.load(f)

    x = T.matrix('x')
    y = model.get_output(x)
    output_func = theano.function(inputs=[x], outputs=(y >= threshold))

    # Load data
    image_data = DataLoader('../data/cuhk_small.mat', verbose=True)

    # Pre-processing
    print "Pre-processing ..."

    images = image_data.get_all_images()
    images = [_input_preproc(image) for image in images]
    images = imageproc.images2mat(images).astype(theano.config.floatX)

    # Compute masks
    print "Computing masks ..."

    masks = output_func(images)

    # Save masks
    print "Saving data ..."

    mask_data = DataSaver()

    cur_index = 0
    for gid in xrange(image_data.get_n_groups()):
        m, v = image_data.get_n_pedes_views(gid)
        mask_data.add_group(m, v)

        for pid in xrange(m):
            n_images = image_data.get_n_images(gid, pid)

            for vid, n in enumerate(n_images):
                view_masks = [0] * n
                for k in xrange(n):
                    mask = masks[cur_index, :]
                    mask = mask.reshape(160, 80, 1)
                    orig_image = image_data.get_image(gid, pid, vid, k)
                    orig_image = imageproc.imresize(orig_image, (160, 80, 3))
                    view_masks[k] = (mask * orig_image).astype(numpy.uint8)
                    cur_index += 1

                mask_data.set_images(gid, pid, vid, view_masks)

    mask_data.save('../data/cuhk_small_masked.mat')
Exemple #3
0
    def show_pid(self, pid):
        # Show images
        self._gallery.itemSelectionChanged.disconnect(self.update_attr)
        self._gallery.clear()

        for v in xrange(self.mat_images.shape[1]):
            if self.mat_images[pid, v].size == 0: break
            for k in xrange(self.mat_images[pid, v].shape[1]):
                img = self.mat_images[pid, v][0, k]
                img = ndarray2qimage(imageproc.imresize(img, (256, 96)))
                item = QtGui.QListWidgetItem(
                    QtGui.QIcon(QtGui.QPixmap.fromImage(img)),
                    '{0},{1}'.format(v, k))
                self._gallery.addItem(item)
                item.setSelected(True)

        self._gallery.itemSelectionChanged.connect(self.update_attr)

        # Show attributes
        self.update_attr()

        # Show status
        self._status.setText('{0} / {1}'.format(pid+1, self.mat_images.shape[0]))
Exemple #4
0
 def imgprep(img):
     img = imageproc.imresize(img, (80, 30))
     img = imageproc.subtract_luminance(img)
     img = numpy.rollaxis(img, 2)
     return img
Exemple #5
0
 def imgprep(img):
     img = imageproc.imresize(img, (80, 30))
     img = rgb2lab(img)[:,:,1:]
     img = numpy.rollaxis(img, 2)
     return img
 def imgprep(img):
     img = imageproc.imresize(img, (80, 30))
     img = rgb2lab(img)[:, :, 1:]
     img = numpy.rollaxis(img, 2)
     return img
Exemple #7
0
def _preproc(image):
    image = imageproc.imresize(image, (80, 40, 3))
    image = numpy.rollaxis(image, 2)
    # image = imageproc.subtract_luminance(image)
    # image = imageproc.scale_per_channel(image, [0, 1])
    return image / 255.0
def _input_preproc(image):
    image = imageproc.imresize(image, (160, 80, 3))
    image = imageproc.subtract_luminance(image)
    image = imageproc.scale_per_channel(image, [0, 1])
    image = numpy.rollaxis(image, 2)
    return image
Exemple #9
0
def _preproc_func(image):
    image = imageproc.imresize(image, (80, 40), keep_ratio='height')
    image = imageproc.subtract_luminance(image)
    image = numpy.rollaxis(image, 2)
    return numpy.tanh(image)
Exemple #10
0
 def imgprep(img):
     img = imageproc.imresize(img, (80, 30))
     img = imageproc.subtract_luminance(img)
     img = numpy.rollaxis(img, 2)
     return img
Exemple #11
0
def _preproc_func(image):
    image = imageproc.imresize(image, (80, 40), keep_ratio='height')
    image = imageproc.subtract_luminance(image)
    image = numpy.rollaxis(image, 2)
    return numpy.tanh(image)
Exemple #12
0
def _preproc(image):
    image = imageproc.imresize(image, (80, 40, 3))
    image = numpy.rollaxis(image, 2)
    # image = imageproc.subtract_luminance(image)
    # image = imageproc.scale_per_channel(image, [0, 1])
    return image / 255.0
Exemple #13
0
def _input_preproc(image):
    image = imageproc.imresize(image, (160, 80, 3))
    image = imageproc.subtract_luminance(image)
    image = imageproc.scale_per_channel(image, [0, 1])
    image = numpy.rollaxis(image, 2)
    return image