FastSAM icon indicating copy to clipboard operation
FastSAM copied to clipboard

FastSAM with FacebookSAM output format?

Open hyfung opened this issue 2 years ago • 0 comments

I am moving from Facebook SAM to FastSAM for performance

This is the output from Facebook SAM which is a one-dimension Tensor object, a mask

tensor([[[[ 0.0513,  0.0712,  0.0959,  ..., -0.0717,  0.0165, -0.0367],
          [ 0.0574,  0.0634,  0.0914,  ..., -0.0781, -0.1138, -0.0455],
          [ 0.0157,  0.0310,  0.0440,  ..., -0.0873, -0.0347, -0.1231],
          ...,
          [-0.0402, -0.0600, -0.0629,  ..., -0.1163, -0.1132, -0.1191],
          [-0.0495, -0.0641, -0.0661,  ..., -0.1131, -0.1118, -0.1168],
          [-0.0798, -0.0714, -0.0717,  ..., -0.0992, -0.0963, -0.0890]],

         [[-0.0449, -0.0964, -0.1324,  ..., -0.1508, -0.1199, -0.0934],
          [-0.1326, -0.1667, -0.1602,  ..., -0.0682, -0.1388, -0.0889],
          [-0.1147, -0.1695, -0.1331,  ..., -0.2159, -0.1789, -0.0721],
          ...,
          [ 0.0408,  0.0469,  0.0465,  ...,  0.1070,  0.1099,  0.0866],
          [ 0.0482,  0.0551,  0.0556,  ...,  0.1106,  0.1125,  0.0906],
          [ 0.0450,  0.0694,  0.0697,  ...,  0.1164,  0.1168,  0.0991]],

         [[-0.0713, -0.0456, -0.0633,  ...,  0.0490,  0.0378, -0.0029],
          [-0.0800, -0.0435, -0.0320,  ..., -0.0236,  0.0763,  0.0738],
          [-0.0526, -0.0559, -0.0559,  ..., -0.0367, -0.0532,  0.1031],
          ...,
          [ 0.1038,  0.1466,  0.1499,  ...,  0.2240,  0.2203,  0.2207],
          [ 0.1106,  0.1544,  0.1615,  ...,  0.2243,  0.2158,  0.2178],
          [ 0.1271,  0.1747,  0.1773,  ...,  0.2146,  0.2080,  0.2175]],

         ...,

         [[-0.0022, -0.0022, -0.0024,  ..., -0.0022, -0.0022, -0.0020],
          [-0.0025, -0.0024, -0.0025,  ..., -0.0025, -0.0026, -0.0020],
          [-0.0025, -0.0024, -0.0024,  ..., -0.0024, -0.0024, -0.0020],
          ...,
          [-0.0022, -0.0022, -0.0022,  ..., -0.0023, -0.0024, -0.0023],
          [-0.0022, -0.0022, -0.0022,  ..., -0.0024, -0.0024, -0.0024],
          [-0.0021, -0.0022, -0.0022,  ..., -0.0023, -0.0024, -0.0024]],

         [[-0.0863,  0.0141, -0.0142,  ...,  0.0116,  0.0619,  0.0180],
          [-0.0471,  0.0461,  0.0503,  ..., -0.0294,  0.0006,  0.0611],
          [-0.0185,  0.0570,  0.0842,  ...,  0.0612,  0.0222,  0.0350],
          ...,
          [ 0.3473,  0.3497,  0.3492,  ...,  0.1776,  0.1647,  0.1306],
          [ 0.3304,  0.3298,  0.3299,  ...,  0.1643,  0.1551,  0.1242],
          [ 0.3065,  0.3209,  0.3124,  ...,  0.1530,  0.1493,  0.1357]],

         [[ 0.1114,  0.1155,  0.1297,  ...,  0.0480,  0.0133,  0.0310],
          [ 0.0289,  0.0467,  0.0088,  ...,  0.0373, -0.0320, -0.1146],
          [ 0.0253,  0.0315,  0.0383,  ..., -0.0150,  0.0317, -0.1755],
          ...,
          [ 0.0209,  0.0630,  0.0607,  ..., -0.0191, -0.0278, -0.0416],
          [-0.0036,  0.0483,  0.0479,  ..., -0.0265, -0.0374, -0.0489],
          [-0.0783, -0.0079,  0.0017,  ..., -0.0477, -0.0594, -0.0651]]]],
       device='cuda:0')

While the output of FastSAM is a Tensor with length = 40

Speed: 3.0ms preprocess, 64.9ms inference, 4.5ms postprocess per image at shape (1, 3, 1024, 1024)
tensor([[[0., 0., 0.,  ..., 0., 0., 0.],
         [0., 0., 0.,  ..., 0., 0., 0.],
         [0., 0., 0.,  ..., 0., 0., 0.],
         ...,
         [0., 0., 0.,  ..., 0., 0., 0.],
         [0., 0., 0.,  ..., 0., 0., 0.],
         [0., 0., 0.,  ..., 0., 0., 0.]],

        [[0., 0., 0.,  ..., 0., 0., 0.],
         [0., 0., 0.,  ..., 0., 0., 0.],
         [0., 0., 0.,  ..., 0., 0., 0.],
         ...,
         [0., 0., 0.,  ..., 0., 0., 0.],
         [0., 0., 0.,  ..., 0., 0., 0.],
         [0., 0., 0.,  ..., 0., 0., 0.]],

        [[0., 0., 0.,  ..., 0., 0., 0.],
         [0., 0., 0.,  ..., 0., 0., 0.],
         [0., 0., 0.,  ..., 0., 0., 0.],
         ...,
         [0., 0., 0.,  ..., 0., 0., 0.],
         [0., 0., 0.,  ..., 0., 0., 0.],
         [0., 0., 0.,  ..., 0., 0., 0.]],

        ...,

        [[0., 0., 0.,  ..., 0., 0., 0.],
         [0., 0., 0.,  ..., 0., 0., 0.],
         [0., 0., 0.,  ..., 0., 0., 0.],
         ...,
         [0., 0., 0.,  ..., 0., 0., 0.],
         [0., 0., 0.,  ..., 0., 0., 0.],
         [0., 0., 0.,  ..., 0., 0., 0.]],

        [[0., 0., 0.,  ..., 0., 0., 0.],
         [0., 0., 0.,  ..., 0., 0., 0.],
         [0., 0., 0.,  ..., 0., 0., 0.],
         ...,
         [0., 0., 0.,  ..., 0., 0., 0.],
         [0., 0., 0.,  ..., 0., 0., 0.],
         [0., 0., 0.,  ..., 0., 0., 0.]],

        [[0., 0., 0.,  ..., 0., 0., 0.],
         [0., 0., 0.,  ..., 0., 0., 0.],
         [0., 0., 0.,  ..., 0., 0., 0.],
         ...,
         [0., 0., 0.,  ..., 0., 0., 0.],
         [0., 0., 0.,  ..., 0., 0., 0.],
         [0., 0., 0.,  ..., 0., 0., 0.]]], device='cuda:0')

Is there any way to make FastSAM output the same format as Facebook SAM?

hyfung avatar Jul 18 '23 13:07 hyfung