mjkwon2021 / CAT-Net

Official code for CAT-Net: Compression Artifact Tracing Network. Image manipulation detection and localization.
230 stars 25 forks source link

When inference, do I need to convert image to jpg format first? #35

Open wennyHou opened 1 year ago

wennyHou commented 1 year ago

When inference, do I need to convert image to jpg format first? Thanks

CauchyComplete commented 1 year ago

CAT-Net requires a JPEG image as input but the inference code automatically converts a non-JPEG image to JPEG at the very beginning.

FathUMinUllah3797 commented 1 year ago

@CauchyComplete Do we need to convert all the images into jpg before training? If yes, why there are still images with .tiff and .png extension in the lists you provided. Please response to this query as I am getting the following error.

[LIBJPEG ERROR]: Not a JPEG file: starts with 0x49 0x49 [LIBJPEG] Error occurs during reading file. Traceback (most recent call last): File "D:\ImageManipulation\CAT-Net-main\CAT-Net-main\tools\train.py", line 233, in main() File "D:\ImageManipulation\CAT-Net-main\CAT-Net-main\tools\train.py", line 185, in main trainloader, optimizer, model, writer_dict, final_output_dir) File "D:\ImageManipulation\CAT-Net-main\CAT-Net-main\tools..\lib\core\function.py", line 58, in train for i_iter, (images, labels, qtable) in enumerate(trainloader): File "C:\Users\MSI\anaconda3\envs\cat\lib\site-packages\torch\utils\data\dataloader.py", line 521, in next data = self._next_data() File "C:\Users\MSI\anaconda3\envs\cat\lib\site-packages\torch\utils\data\dataloader.py", line 561, in _next_data data = self._dataset_fetcher.fetch(index) # may raise StopIteration File "C:\Users\MSI\anaconda3\envs\cat\lib\site-packages\torch\utils\data_utils\fetch.py", line 49, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "C:\Users\MSI\anaconda3\envs\cat\lib\site-packages\torch\utils\data_utils\fetch.py", line 49, in data = [self.dataset[idx] for idx in possibly_batched_index] File "D:\ImageManipulation\CAT-Net-main\CAT-Net-main\tools..\Splicing\data\data_core.py", line 99, in getitem return self.dataset_list[index//self.smallest].get_tamp(index%self.smallest) File "D:\ImageManipulation\CAT-Net-main\CAT-Net-main\tools..\Splicing\data\dataset_CASIA.py", line 55, in get_tamp return self._create_tensor(tamp_path, mask) File "D:\ImageManipulation\CAT-Net-main\CAT-Net-main\tools..\Splicing\data\AbstractDataset.py", line 111, in _create_tensor DCT_coef, qtables = self._get_jpeg_info(im_path) File "D:\ImageManipulation\CAT-Net-main\CAT-Net-main\tools..\Splicing\data\AbstractDataset.py", line 44, in _get_jpeg_info jpeg = jpegio.read(str(im_path)) File "C:\Users\MSI\anaconda3\envs\cat\lib\site-packages\jpegio\io.py", line 10, in read obj.read(fpath) File "jpegio\decompressedjpeg.pyx", line 62, in jpegio.decompressedjpeg.DecompressedJpeg.read File "jpegio\decompressedjpeg.pyx", line 80, in jpegio.decompressedjpeg.DecompressedJpeg.read OSError: An error has occurs in reading the file. [LIBJPEG ERROR]: Improper call to JPEG library in state 0

CauchyComplete commented 1 year ago

In the inference dataset(dataset='arbitrary'), non-JPEG images are automatically converted to JPEG files and plugged into the model: https://github.com/mjkwon2021/CAT-Net/blob/f1716b0849eb4d94687a02c25bf97229b495bf9e/tools/infer.py#L75

During training, we should manually convert them into JPEG files.

I implemented it like this for speed-up training because training uses converted files multiple times.