Ejemplo n.º 1
0
    def _testMiniAlexNet(self, order):
        # First, we get all the random initialization of parameters.
        model = self._MiniAlexNetNoDropout(order)
        workspace.ResetWorkspace()
        workspace.RunNetOnce(model.param_init_net)
        inputs = dict([(str(name), workspace.FetchBlob(str(name)))
                       for name in model.params])
        if order == "NCHW":
            inputs["data"] = np.random.rand(4, 3, 227, 227).astype(np.float32)
        else:
            inputs["data"] = np.random.rand(4, 227, 227, 3).astype(np.float32)
        inputs["label"] = np.array([1, 2, 3, 4]).astype(np.int32)

        cpu_device = caffe2_pb2.DeviceOption()
        cpu_device.device_type = caffe2_pb2.CPU
        gpu_device = caffe2_pb2.DeviceOption()
        gpu_device.device_type = caffe2_pb2.CUDA

        checker = device_checker.DeviceChecker(1e-5, [cpu_device, gpu_device])
        ret = checker.CheckNet(
            model.net.Proto(),
            inputs,
            # The indices sometimes may be sensitive to small numerical differences
            # in the input, so we ignore checking them.
            ignore=['_pool1_idx', '_pool2_idx', '_pool5_idx'])
        self.assertEqual(ret, True)
Ejemplo n.º 2
0
    def testMNISTNetworks(self):
        # First, we get all the random initialization of parameters.
        init_net, train_net = self._MNISTNetworks()
        workspace.ResetWorkspace()
        workspace.RunNetOnce(init_net)
        inputs = dict([(str(name), workspace.FetchBlob(str(name)))
                       for name in workspace.Blobs()])
        cpu_device = caffe2_pb2.DeviceOption()
        cpu_device.device_type = caffe2_pb2.CPU
        gpu_device = caffe2_pb2.DeviceOption()
        gpu_device.device_type = caffe2_pb2.CUDA

        checker = device_checker.DeviceChecker(1e-2, [cpu_device, gpu_device])
        ret = checker.CheckNet(train_net.Proto(), inputs)
        self.assertEqual(ret, True)
Ejemplo n.º 3
0
import numpy as np
from pycaffe2 import core, device_checker, gradient_checker, workspace
from caffe2.proto import caffe2_pb2, caffe2_legacy_pb2

import sys
import unittest

if workspace.has_gpu_support and workspace.NumberOfGPUs() > 0:
    gpu_device_option = caffe2_pb2.DeviceOption()
    gpu_device_option.device_type = caffe2_pb2.CUDA
    cpu_device_option = caffe2_pb2.DeviceOption()
    device_checker = device_checker.DeviceChecker(
        0.01, [gpu_device_option, cpu_device_option])
    gradient_checkers = [
        gradient_checker.GradientChecker(0.005, 0.05, gpu_device_option,
                                         "gpu_checker_ws"),
        gradient_checker.GradientChecker(0.01, 0.05, cpu_device_option,
                                         "cpu_checker_ws"),
    ]
else:
    cpu_device_option = caffe2_pb2.DeviceOption()
    device_checker = device_checker.DeviceChecker(0.01, [cpu_device_option])
    gradient_checkers = [
        gradient_checker.GradientChecker(0.01, 0.05, cpu_device_option,
                                         "cpu_checker_ws")
    ]


class TestConvLegacyPooling(unittest.TestCase):
    def setUp(self):
        self.test_configs = [