def webp_enc(self, x, quality):
     shape = (8, 16)
     data = copy.copy(x)
     fmap_images_with_info = feature_maps_to_image(
         data, shape, is_display=0, is_save=0)
     encode_param = [int(cv2.IMWRITE_WEBP_QUALITY), quality]
     result, encimg = cv2.imencode(
         '.webp', fmap_images_with_info[0][0], encode_param)
     self.compressed_mem = len(encimg)
     print(len(encimg), "length of encoded image")
     res = (encimg, fmap_images_with_info[0][1])
     return res
 def jpeg_enc(self, feature_maps, quality):
     """
     feature_maps: output tensor of feature maps in shape (1, 78, 78, 128)
     quality: quality of JPEG lossy compression from 0 - 100
     return: sliced image of feature maps, pixel from 0 - 255
     """
     shape = (8, 16)
     fmap_images_with_info = feature_maps_to_image(
         feature_maps, shape, is_display=0, is_save=0)
     encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), quality]
     result, encimg = cv2.imencode(
         '.jpg', fmap_images_with_info[0][0], encode_param)
     self.compressed_mem = len(encimg)
     # print(len(encimg), "length of encoded image")
     res = (encimg, fmap_images_with_info[0][1])
     return res