def test_conv_works_with_npmat(plot=False): # use the same data for both experiments: from pylab import randn color = 0 image_size = img_size = 10 filter_size = 2 num_groups = 2 num_images_per_group = 3 num_filters_per_group = 2 iorder = 1 color_mult = [1, 3][color] images = rand(num_groups, num_images_per_group, color_mult, image_size, image_size) < 0.1 filters = randn(num_groups, num_filters_per_group, color_mult, filter_size, filter_size) filters[:, 0] = 1 ans = [None] * 2 print "a" for (i, gx) in enumerate([g, gc]): conv.g = gx conv._cu = gx._cudamat # I don't get it. And I really need to get if I'm to apply it anywhere at all. # How are these things working? ans[i] = conv.conv(gx.garray(images), gx.garray(filters), targets=None, iorder=iorder).asarray() print "b" print abs(ans[0] - ans[1]).max() # quite successful, indeed. It's weird as hell. The strangest # thing is that it used to work. if plot: from pylab import show, subplot subplot(221) show(images[1, 1, 0, :, :]) subplot(223) show(ans[0][1, 1, 0, :, :]) subplot(224) show(ans[1][1, 1, 0, :, :]) return ans
def test_conv(plot=False, iorder=1, color=1, g=1, c=None, f=1, i=1): # use the same data for both experiments: from pylab import randn image_size = img_size = 10 filter_size = 2 num_groups = 4 num_images_per_group = 3 num_filters_per_group = 6 color_mult = [1, 3][color] images = rand(num_groups, num_images_per_group, color_mult, image_size, image_size) < 0.02 filters = randn(num_groups, num_filters_per_group, color_mult, filter_size, filter_size) filters[:, 0, :, :, :] = 1 if color_mult == 3: filters[:, :, 0, :, :] = 0 # to have only one color filter, or else we won't have filters[:, :, 2, :, :] = 0 # pretty responses. ans = [None] * 2 print "a" for (i, gx) in enumerate([gnumpy, gc]): conv.g = gx conv._cu = gx._cudamat # I don't get it. And I really need to get if I'm to apply it anywhere at all. # How are these things working? ans[i] = conv.conv(gx.garray(images), gx.garray(filters), targets=None, iorder=iorder).asarray() print "b" print abs(ans[0] - ans[1]).max() # quite successful, indeed. It's weird as hell. The strangest # thing is that it used to work. if plot: if c is None: c = [0, 1][color] from pylab import show, subplot if iorder == 1: subplot(221) show(images[g, i, c, :, :]) subplot(223) show(ans[0][g, i, f, :, :]) subplot(224) show(ans[1][g, i, f, :, :]) else: subplot(221) show(images[g, i, c, :, :]) subplot(223) show(ans[0][g, f, i, :, :]) subplot(224) show(ans[1][g, f, i, :, :]) # subplot(224); show(ans[0][1,1,1,:,:]) return ans