coremltools icon indicating copy to clipboard operation
coremltools copied to clipboard

Update ops.py

Open DdHms opened this issue 3 years ago • 2 comments

The condition can return a list and all should work the same as if returned tuple. The comment above expresses the case of a returned single item but does not account for an item of type list

DdHms avatar Jul 18 '22 19:07 DdHms

Thanks for the pull request @DdHms. Does this fix and issue you are having? If so, please share some details.

TobyRoseman avatar Jul 18 '22 20:07 TobyRoseman

while trying to script the following model:

class SEG_COREML(torch.nn.Module):
        def __init__(self):
            super().__init__()
            self.non_mem = traced_no_mem
            self.mem_frame = traced_mem_frame
        
        def forward(self, img, init_mask, key_k, key_v, frame_num, mem_every):
         
                frac = frame_num[0] / mem_every[0]
                if frac.double() == frac.int():
                    segmentation, key_k, key_v = self.mem_frame(img, key_k, key_v)
                else:
                    segmentation, key_k, key_v = self.non_mem(img, key_k, key_v)
            return segmentation, key_k, key_v

This line returned a list of the 3 outputs from my _if op but since it wasn't a tuple it was wrapped into a tuple at line and then failed the assertion in line because len(cond) was now 1 instead of 3

DdHms avatar Jul 19 '22 07:07 DdHms

I have rebase this change. CI: https://gitlab.com/coremltools1/coremltools/-/pipelines/629008351

TobyRoseman avatar Sep 01 '22 16:09 TobyRoseman