Пример #1
0
    def setUp(self):
        self.op = FilterActs(module_stride=self.module_stride, openmp=False)
        self.op_omp = FilterActs(module_stride=self.module_stride, openmp=True)

        self.s_filters_list = [
            theano.shared(rand(fshape, self.dtype))
            for fshape in self.fshape_list
        ]
        self.s_images_list = [
            theano.shared(rand(ishape, self.dtype))
            for ishape in self.ishape_list
        ]
Пример #2
0
    def setUp(self):
        self.op = FilterActs(self.module_stride)

        for i in range(self.nbTests):
            self.s_images_list = [
                theano.shared(rand(ishape, self.dtype))
                for ishape in self.ishape_list
            ]
            self.s_filters_list = [
                theano.shared(rand(fshape, self.dtype))
                for fshape in self.fshape_list
            ]
Пример #3
0
def Toncv(image,filters,module_stride=1):
    op = FilterActs(module_stride)
    return op(image,filters)
Пример #4
0
 def test_op_eq(self):
     assert FilterActs(1) == FilterActs(1)
     assert not (FilterActs(1) != FilterActs(1))
     assert (FilterActs(2) != FilterActs(1))
     assert FilterActs(1) != None
Пример #5
0
    def testMainOpSpeed(self):
        def do_time(output, mode=theano.Mode(linker='c')):
            f = theano.function([], output, mode=mode)
            t0 = time.time()
            [f() for i in range(self.n_calls)]
            t1 = time.time()
            return t1 - t0

        for i in range(self.nbTests):
            print "image shape", self.ishape_list[i]
            print "filter shape", self.fshape_list[i]
            # Generate theano functions to run the op in python and in C
            output = self.op(self.s_images_list[i], self.s_filters_list[i])
            output_omp = self.op_omp(self.s_images_list[i],
                                     self.s_filters_list[i])
            output_fcols = FilterActs(
                module_stride=self.module_stride,
                openmp=False,
                fcols=self.fshape_list[i][-1])(self.s_images_list[i],
                                               self.s_filters_list[i])
            output_fcols_omp = FilterActs(
                module_stride=self.module_stride,
                openmp=True,
                fcols=self.fshape_list[i][-1])(self.s_images_list[i],
                                               self.s_filters_list[i])
            output_frows_fcols = FilterActs(
                module_stride=self.module_stride,
                openmp=False,
                fcols=self.fshape_list[i][-1],
                frows=self.fshape_list[i][-2])(self.s_images_list[i],
                                               self.s_filters_list[i])
            output_frows_fcols_omp = FilterActs(
                module_stride=self.module_stride,
                openmp=True,
                fcols=self.fshape_list[i][-1],
                frows=self.fshape_list[i][-2])(self.s_images_list[i],
                                               self.s_filters_list[i])

            # Run the OP in python
            py_t = do_time(output, mode=theano.Mode(linker='py'))
            print "py", py_t

            # Run the OP in C
            c_t = do_time(output, mode=theano.Mode(linker='c|py'))
            print "c|py", c_t, "speed up", py_t / c_t

            # Run the OP in C with fcols
            c_t_fcols = do_time(output_fcols)
            print "c fcols", c_t_fcols, "speed up", py_t / c_t_fcols

            # Run the OP in C with fcols, frows
            c_t_frows_fcols = do_time(output_frows_fcols)
            print "c frows_fcols", c_t_frows_fcols, "speed up", py_t / c_t_frows_fcols

            # Run the Op in C with openmp
            if theano.config.openmp:
                c_omp_t = do_time(output_omp)
                print "omp c", c_omp_t, "speed up python", py_t / c_omp_t, "speed up c", c_t / c_omp_t

                c_omp_fcols_t = do_time(output_fcols_omp)
                print "omp c fcols", c_omp_fcols_t, "speed up python", py_t / c_omp_fcols_t, "speed up c fcols", c_t_fcols / c_omp_fcols_t

                c_omp_frows_fcols_t = do_time(output_frows_fcols_omp)
                print "omp c fcols", c_omp_frows_fcols_t, "speed up python", py_t / c_omp_frows_fcols_t, "speed up c frows_fcols", c_t_frows_fcols / c_omp_frows_fcols_t