Best Python code snippet using avocado_python
lpsnet.py
Source:lpsnet.py
...75 raise NotImplementedError76class LPSNet1Path(BaseSegNet):77 def __init__(self, depth, width, resolution, num_classes=19, deploy=False):78 super(LPSNet1Path, self).__init__(depth, width, resolution, num_classes)79 self._check_resolution()80 self.net = BaseNet(self.depth, self.width, deploy)81 self.head = nn.Conv2d(self.width[-1], self.num_classes, 1, 1, 0, bias=True)82 def forward(self, x):83 return self.head(self.net(self._preprocess_input(x)))84 def _preprocess_input(self, x):85 r = self.resolution[0]86 return upsample(x, (int(x.shape[-2] * r), int(x.shape[-1] * r)))87 def _check_resolution(self):88 assert self.resolution[0] > 089 for i in range(1, len(self.resolution)):90 assert self.resolution[i] == 091class LPSNet2Path(BaseSegNet):92 def __init__(self, depth, width, resolution, num_classes=19, deploy=False):93 super(LPSNet2Path, self).__init__(depth, width, resolution, num_classes)94 self._check_resolution()95 self.netH = BaseNet(self.depth, self.width, deploy)96 self.netL = BaseNet(self.depth, self.width, deploy)97 self.head = nn.Conv2d(self.width[-1] * 2, self.num_classes, 1, 1, 0, bias=True)98 def _check_resolution(self):99 assert len(self.resolution) >= 2100 assert self.resolution[0] > 0101 assert self.resolution[1] > 0102 assert self.resolution[0] >= self.resolution[1]103 for i in range(2, len(self.resolution)):104 assert self.resolution[i] == 0105 def _preprocess_input(self, x):106 r1 = self.resolution[0]107 r2 = self.resolution[1]108 x1 = upsample(x, (int(x.shape[-2] * r1), int(x.shape[-1] * r1)))109 x2 = upsample(x, (int(x.shape[-2] * r2), int(x.shape[-1] * r2)))110 return x1, x2111 def forward(self, x):112 xh, xl = self._preprocess_input(x)113 xh, xl = self.netH.stages[0](xh), self.netL.stages[0](xl)114 xh, xl = self.netH.stages[1](xh), self.netL.stages[1](xl)115 xh, xl = self.netH.stages[2](xh), self.netL.stages[2](xl)116 xh, xl = bi_interaction(xh, xl)117 xh, xl = self.netH.stages[3](xh), self.netL.stages[3](xl)118 xh, xl = bi_interaction(xh, xl)119 xh, xl = self.netH.stages[4](xh), self.netL.stages[4](xl)120 x_cat = torch.cat([xh, upsample(xl, (int(xh.shape[-2]), int(xh.shape[-1])))], dim=-3)121 return self.head(x_cat)122class LPSNet3Path(BaseSegNet):123 def __init__(self, depth, width, resolution, num_classes=19, deploy=False):124 super(LPSNet3Path, self).__init__(depth, width, resolution, num_classes)125 self._check_resolution()126 self.net1 = BaseNet(self.depth, self.width, deploy)127 self.net2 = BaseNet(self.depth, self.width, deploy)128 self.net3 = BaseNet(self.depth, self.width, deploy)129 self.head = nn.Conv2d(self.width[-1] * 3, self.num_classes, 1, 1, 0, bias=True)130 def _check_resolution(self):131 assert len(self.resolution) >= 3132 assert self.resolution[0] > 0133 assert self.resolution[1] > 0134 assert self.resolution[2] > 0135 assert self.resolution[0] >= self.resolution[1] >= self.resolution[2]136 for i in range(3, len(self.resolution)):137 assert self.resolution[i] == 0138 def _preprocess_input(self, x):139 r1 = self.resolution[0]140 r2 = self.resolution[1]141 r3 = self.resolution[2]142 x1 = upsample(x, (int(x.shape[-2] * r1), int(x.shape[-1] * r1)))143 x2 = upsample(x, (int(x.shape[-2] * r2), int(x.shape[-1] * r2)))144 x3 = upsample(x, (int(x.shape[-2] * r3), int(x.shape[-1] * r3)))...
test_resolver.py
Source:test_resolver.py
...132 self.assertEqual(resolution.args, ())133 self.assertEqual(resolution.kwargs, {})134 self.assertEqual(resolution.tags, {"flattag": None, "foo": {"bar"}})135 def test_dont_detect_non_avocado(self):136 def _check_resolution(resolution, name):137 self.assertEqual(resolution.kind, "python-unittest")138 self.assertEqual(resolution.uri, f"{path}:{name}")139 self.assertEqual(resolution.args, ())140 self.assertEqual(resolution.kwargs, {})141 self.assertEqual(resolution.tags, {})142 self.assertEqual(resolution.dependencies, [])143 path = os.path.join(144 os.path.dirname(os.path.dirname(os.path.dirname(__file__))),145 ".data",146 "safeloader",147 "data",148 "dont_detect_non_avocado.py",149 )150 res = PythonUnittestResolver().resolve(path)151 self.assertEqual(res.reference, path)152 self.assertEqual(res.result, resolver.ReferenceResolutionResult.SUCCESS)153 self.assertEqual(len(res.resolutions), 3)154 _check_resolution(res.resolutions[0], "StaticallyNotAvocadoTest.test")155 _check_resolution(res.resolutions[1], "NotTest.test2")156 _check_resolution(res.resolutions[2], "NotTest.test")157if __name__ == "__main__":...
validate_output_resolution.py
Source:validate_output_resolution.py
...29 reformat = inode30 return reformat31 @classmethod32 def get_invalid(cls, instance):33 def _check_resolution(instance, reformat):34 root_width = instance.data["resolutionWidth"]35 root_height = instance.data["resolutionHeight"]36 write_width = reformat.format().width()37 write_height = reformat.format().height()38 if (root_width != write_width) or (root_height != write_height):39 return None40 else:41 return True42 # check if reformat is in render node43 reformat = cls.get_reformat(instance)44 if not reformat:45 return cls.missing_msg46 # check if reformat is set to correct root format47 correct_format = _check_resolution(instance, reformat)48 if not correct_format:49 return cls.resolution_msg50 @classmethod51 def repair(cls, instance):52 invalid = cls.get_invalid(instance)53 grp_node = instance[0]54 if cls.missing_msg == invalid:55 # make sure we are inside of the group node56 with grp_node:57 # find input node and select it58 _input = None59 for inode in instance:60 if inode.Class() != "Input":61 continue...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!