| 167 | |
| 168 | |
| 169 | class CVPipeline(Pipeline): |
| 170 | def __init__( |
| 171 | self, |
| 172 | batch_size, |
| 173 | output_type, |
| 174 | input_type, |
| 175 | use_input, |
| 176 | num_threads=3, |
| 177 | device_id=0, |
| 178 | num_gpus=1, |
| 179 | inv_map=False, |
| 180 | ): |
| 181 | super(CVPipeline, self).__init__( |
| 182 | batch_size, num_threads, device_id, seed=7865, exec_async=False, exec_pipelined=False |
| 183 | ) |
| 184 | self.use_input = use_input |
| 185 | self.name = "cv" |
| 186 | self.input = ops.readers.Caffe( |
| 187 | path=caffe_db_folder, shard_id=device_id, num_shards=num_gpus |
| 188 | ) |
| 189 | self.decode = ops.decoders.Image(device="cpu", output_type=types.RGB) |
| 190 | if self.use_input: |
| 191 | self.transform_source = ops.ExternalSource( |
| 192 | lambda: gen_transforms(self.max_batch_size, 10) |
| 193 | ) |
| 194 | self.warp = ops.PythonFunction( |
| 195 | function=CVWarp(output_type, input_type, inv_map=inv_map), output_layouts="HWC" |
| 196 | ) |
| 197 | else: |
| 198 | self.warp = ops.PythonFunction( |
| 199 | function=CVWarp( |
| 200 | output_type, input_type, [[0.1, 0.9, 10], [0.8, -0.2, -20]], inv_map |
| 201 | ), |
| 202 | output_layouts="HWC", |
| 203 | ) |
| 204 | self.iter = 0 |
| 205 | |
| 206 | def define_graph(self): |
| 207 | self.jpegs, self.labels = self.input(name="Reader") |
| 208 | images = self.decode(self.jpegs) |
| 209 | if self.use_input: |
| 210 | self.transform = self.transform_source() |
| 211 | outputs = self.warp(images, self.transform) |
| 212 | else: |
| 213 | outputs = self.warp(images) |
| 214 | return outputs |
| 215 | |
| 216 | |
| 217 | def compare(pipe1, pipe2, max_err): |