def test_initialize_stripe(self): """Test that we can initialize a stripe pattern""" stripes = patterns.StripePattern(WHITE, BLACK) self.assertEqual(stripes.color_a, WHITE) self.assertEqual(stripes.color_b, BLACK) self.assertEqual(stripes.transform, transforms.Identity(4))
def test_default_view(self): """Test that the view transform for the default view is identity""" from_point = points.Point(0, 0, 0) to_point = points.Point(0, 0, -1) up = vectors.Vector(0, 1, 0) result = transforms.ViewTransform(from_point, to_point, up) self.assertEqual(result, transforms.Identity(4))
def __init__(self, material: Union[materials.Material, None] = None): self.id = uuid.uuid4() self.set_transform(transforms.Identity(4)) if material is None: self.set_material(materials.Material()) else: self.set_material(material)
def test_identity_matrix_mult(self): """Test we can identify the identity matrix by a matrix and tuple""" ident = transforms.Identity(3) M = matrices.Matrix(3, 3) M.set_row(0, [1, 2, 3]) M.set_row(1, [3, 2, 1]) M.set_row(2, [2, 4, 6]) M2 = M * ident self.assertEqual(M2, M) t = tuples.Tuple(["a", "b", "c"], 1, 2, 3) t2 = ident * t self.assertEqual(t2, t)
def __init__(self, hsize: int, vsize: int, field_of_view: float) -> None: self.hsize = hsize self.vsize = vsize self.field_of_view = field_of_view half_view = math.tan(field_of_view / 2) aspect = hsize / vsize if aspect >= 1: self.half_width = half_view self.half_height = half_view / aspect else: self.half_width = half_view * aspect self.half_height = half_view self.pixel_size = self.half_width * 2 / self.hsize self.transform = transforms.Identity(4)
def main(epochs, batch_size, learn_angle, angle_lr): transform = torchvision.transforms.Compose([ transforms.RandomRotation(30), transforms.Identity() if learn_angle else transforms.Free(), transforms.ToTensor(), transforms.Normalize() ]) set_train = dataset.MNIST(root='./data', train=True, download=True, transform=transform) set_test = dataset.MNIST(root='./data', train=False, download=True, transform=transform) loader_train = torch.utils.data.DataLoader(set_train, batch_size=batch_size, shuffle=True, num_workers=2) loader_test = torch.utils.data.DataLoader(set_test, batch_size=batch_size, shuffle=False, num_workers=2) nn = model.Net(learn_angle) if torch.cuda.is_available(): nn.cuda() optimizer = optim.SGD(nn.parameters(), lr=0.001, momentum=0.9) VIEW_INTERVAL = 100 for epoch in range(epochs): acc_loss = 0.0 running_loss = 0.0 for i, sample in enumerate(loader_train): x, y = pack(sample, learn_angle) optimizer.zero_grad() y_pred = nn(x) loss = model.loss(y_pred, y, angle_lr) loss.backward() optimizer.step() # report loss acc_loss += loss.item() if i % VIEW_INTERVAL == VIEW_INTERVAL - 1: running_loss = acc_loss / VIEW_INTERVAL click.secho( f"\rEpoch {epoch+1}, iteration {i+1}; " f"loss: {(running_loss):.3f}; ", err=True, nl=False) acc_loss = 0.0 # testing count_correct = 0 count_total = 0 for sample in loader_test: x, labels = pack(sample, learn_angle) y_pred = nn(Variable(x)) if learn_angle: labels = labels[0] y_pred = y_pred[0] _, labels_pred = torch.max(y_pred.data, 1) c = (labels_pred == labels).squeeze() count_correct += c.sum().item() count_total += len(c) click.secho( f"\rEpoch {epoch+1}; loss: {(running_loss):.3f}; " f"Test Acc: {100.0 * count_correct / count_total :.2f}%", err=True, nl=False) running_loss = 0 click.secho('', err=True)
def test_identity_matrix_transpose(self): """Test that the transpose of the identity matrix is identity""" ident = transforms.Identity(5) self.assertEqual(ident.transpose(), ident)
def __init__(self, array, transform=transforms.Identity()): Parentable.__init__(self) self._array = np.asarray(np.atleast_1d(array), dtype=np.float64) self.transform = transform self.prior = None self.fixed = False
def __init__(self): self.set_transform(transforms.Identity(4))
def test_default_transform(self): """Test that we get the identity matrix as the default transform""" s = shapes.Sphere() self.assertEqual(s.transform, transforms.Identity(4))