solution for jpegpy
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
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
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