Пример #1
0
    def test_opencl_implementation(self):
        scikits.image.color.lazyopts.enable()
        colspaces = ['HSV', 'RGB CIE', 'XYZ']
        colfuncs_from = [hsv2rgb, rgbcie2rgb, xyz2rgb]
        colfuncs_to = [rgb2hsv, rgb2rgbcie, rgb2xyz]

        # create an input, and make some promises about it.
        img = lazy.lnumpy.NdarraySymbol.new(value=self.colbars_array)
        img.value = img.value.astype('float32')
        img.contiguous=True
        img.shape = (None, None, 3)
        img.dtype=np.dtype('float32')

        assert_almost_equal(convert_colorspace(self.colbars_array, 'RGB',
                                               'RGB'), self.colbars_array)
        for i, space in enumerate(colspaces):
            print 'test: colorspace', space
            gt = colfuncs_from[i](img)
            eval_gt = lazy.function([img], gt)
            assert_almost_equal(convert_colorspace(self.colbars_array, space,
                                                  'RGB'), eval_gt(img.value))

            gt = colfuncs_to[i](img)
            eval_gt = lazy.function([img], gt)
            #eval_gt.print_eval_order()
            assert_almost_equal(convert_colorspace(self.colbars_array, 'RGB',
                                                   space), eval_gt(img.value))
Пример #2
0
    def test_opencl_speed(self):
        scikits.image.color.lazyopts.enable()
        colspaces = ['RGB CIE', 'XYZ']
        colfuncs_from = [ rgbcie2rgb, xyz2rgb]
        colfuncs_to = [ rgb2rgbcie, rgb2xyz]
        imgdata = np.random.RandomState(234).rand(1600,1200,3).astype('float32')

        # create an input, and make some promises about it.
        img = lazy.lnumpy.NdarraySymbol.new()
        img.contiguous=True
        img.shape = (None, None, 3)
        img.dtype=np.dtype('float32')

        for i, space in enumerate(colspaces):
            print 'test: colorspace', space
            gt = colfuncs_from[i](img)
            scikits.image.color.lazyopts.enable()
            fn_yes_cl = lazy.function([img], gt)
            scikits.image.color.lazyopts.disable()
            fn_no_cl = lazy.function([img], gt)

            fn_yes_cl.reuse_computed = True # optimization
            print 'fn_yes_cl:'
            fn_yes_cl.print_eval_order()

            def with_cl():
                return fn_yes_cl(imgdata)
            def without_cl():
                return fn_no_cl(imgdata)
            def orig_fn():
                return convert_colorspace(imgdata, space, 'RGB')

            orig_fn_times = timeit.Timer(orig_fn).repeat(3,3)
            without_cl_times = timeit.Timer(without_cl).repeat(3,3)
            with_cl_times = timeit.Timer(with_cl).repeat(3,3)
            print 'without_cl times',without_cl_times
            print 'orig_fn times', orig_fn_times
            print 'with_cl times', with_cl_times
            print 'CL speedup:', np.asarray(without_cl_times) / with_cl_times
Пример #3
0
def func(*args, **kwargs):
    return function(
            transform_policy_ctor=lambda :(lambda x:x),
            *args,**kwargs)