CADDM icon indicating copy to clipboard operation
CADDM copied to clipboard

solution for jpegpy

Open AbitGo opened this issue 11 months ago • 2 comments

someone meet problem as "ImportError: cannot import name '_jpegpy' from partially initialized module 'lib.data_preprocess.utils.jpegpy' (most likely due to a circular import) (/home/dancer/project_xm/CADDM-master/lib/data_preprocess/utils/jpegpy/init.py)"

issue:https://github.com/megvii-research/CADDM/issues/56#issue-2740636831

but, it is so difficult for me to compile jpegpy.so, emmmm beacause i use windows.so i give a direct solution for this problem: 1.enter the file :"CADDM-master\lib\data_preprocess\utils\jpegpy": 2.replace the following code to originial code:

import imageio import numpy as np from io import BytesIO

def jpeg_encode(img: np.array, quality=80): img_byte_arr = BytesIO() imageio.imwrite(img_byte_arr, img, format='JPEG', quality=quality) return img_byte_arr.getvalue()

def jpeg_decode(code: bytes): img = imageio.imread(code) return img

AbitGo avatar Jan 06 '25 06:01 AbitGo

In lib/data_preprocess/utils/jpegpy/jpegpy.py change the code to the below code everything is fine you don't need to recompile anything

#!/usr/bin/env mdl import cv2 import numpy as np

import cv2 import numpy as np

def jpeg_encode(img: np.array, quality=80): from . import _jpegpy # Move import inside the function img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) return _jpegpy.encode(img, quality)

def jpeg_decode(code: bytes): from . import _jpegpy # Move import inside the function img = _jpegpy.decode(code) return cv2.cvtColor(img, cv2.COLOR_RGB2BGR)

vim: ts=4 sw=4 sts=4 expandtab

vikrantc672 avatar Jan 17 '25 08:01 vikrantc672

In lib/data_preprocess/utils/jpegpy/jpegpy.py change the code to the below code everything is fine you don't need to recompile anything

#!/usr/bin/env mdl import cv2 import numpy as np

import cv2 import numpy as np

def jpeg_encode(img: np.array, quality=80): from . import _jpegpy # Move import inside the function img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) return _jpegpy.encode(img, quality)

def jpeg_decode(code: bytes): from . import _jpegpy # Move import inside the function img = _jpegpy.decode(code) return cv2.cvtColor(img, cv2.COLOR_RGB2BGR)

if you don't compile jpegpy, training is not going to work

nicolocarissimi avatar Feb 19 '25 20:02 nicolocarissimi