def test_ssd300_infer(): context.set_context(mode=context.GRAPH_MODE, device_target="CPU") model = Model(ssd300_infer()) model.compile() loc, score = model.predict(ts.ones((1, 3, 300, 300))) print(loc.asnumpy(), score.asnumpy())
def test_mobilenetv2_infer(): context.set_context(mode=context.GRAPH_MODE, device_target="CPU") model = Model(mobilenetv2_infer()) model.compile() z = model.predict(ts.ones((1, 3, 224, 224))) print(z.asnumpy())
def test_densenetBC_100(): context.set_context(mode=context.GRAPH_MODE, device_target="CPU") model = Model(densenetBC_100()) model.compile() z = model.predict(ts.ones((1, 3, 32, 32))) print(z.asnumpy())
def test_sequential(): context.set_context(mode=context.GRAPH_MODE, device_target="CPU") net = layers.SequentialLayer([ layers.Conv2d(1, 6, 5, pad_mode='valid', weight_init="ones"), layers.ReLU(), layers.MaxPool2d(kernel_size=2, stride=2) ]) model = Model(net) model.compile() z = model.predict(ts.ones((1, 1, 32, 32))) print(z.asnumpy())
def _initialize_weights(self): self.init_parameters_data() for _, m in self.cells_and_names(): if isinstance(m, layers.Conv2d): n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels m.weight.set_data( Tensor( np.random.normal(0, np.sqrt( 2. / n), m.weight.data.shape).astype("float32"))) if m.bias is not None: m.bias.set_data(ts.zeros(m.bias.data.shape)) elif isinstance(m, layers.BatchNorm2d): m.gamma.set_data(ts.ones(m.gamma.data.shape)) m.beta.set_data(ts.zeros(m.beta.data.shape))