Detecting GAN generated Fake Images using Co-occurrence Matrices

The advent of Generative Adversarial Networks (GANs) has brought about completely novel ways of transforming and manipulating pixels in digital images. GAN based techniques such as Image-to-Image translations, DeepFakes, and other automated methods have become increasingly popular in creating fake images. In this paper, we propose a novel approach to detect GAN generated fake images using a combination of co-occurrence matrices and deep learning. We extract co-occurrence matrices on three color channels in the pixel domain and train a model using a deep convolutional neural network (CNN) framework. Experimental results on two diverse and challenging GAN datasets comprising more than 56,000 images based on unpaired image-to-image translations (cycleGAN [1]) and facial attributes/expressions (StarGAN [2]) show that our approach is promising and achieves more than 99% classification accuracy in both datasets. Further, our approach also generalizes well and achieves good results when trained on one dataset and tested on the other.


Introduction
Recent advances in Machine Learning and Artificial Intelligence have made it tremendously easy to create and synthesize digital manipulations in images and videos. In particular, Generative Adversarial Networks (GANs) [3] have been one of the most promising advancements in image enhancement and manipulation. Due to the success of using GANs for image editing, it is now possible to use a combination of GANs and off-the-shelf image-editing tools to modify digital images to such an extent that it has become difficult to distinguish doctored images from normal ones. The field of digital Image Forensics develops tools and techniques to detect manipulations in digital images such as splicing, resampling and copy move, but the efficacy and robustness of these tools on GAN generated images is yet to be seen. To address this, we propose a novel method to automatically identify GAN generated fake images using techniques that have been inspired from classical steganalysis.
The seminal work on GANs [3] cast the machine learning field of generative modeling as a game theory optimization problem. GANs contain two networks -the first network is a generative network that can generate fake images and the second network is a discirminative network that determines if an image is real or fake. Encoded in the GAN loss function is a min-max game which creates a competition between the generative and discriminative networks. As the discriminative network becomes better at distinguishing between real and fake images, the generative model becomes better at generating fake images.
GANs have been applied to many image processing tasks such as image synthesis, super-resolution and image completion. Inspired by the results of these image processing tasks, GANs have brought in novel attack avenues such as computer generated (CG) faces [4], augmenting faces with CG facial attributes [2], and seamless transfer of texture between images [1], to name a few. Two of the most common applications of GANs include texture or style transfer between images and face manipulations. An example of GAN generated texture translation between images, such as horses-to-zebras and summer-to-winter, is shown in Fig. 1(a). These techniques manipulates the entire image to change the visual appearance of the scene [1]. There has been also tremendous progress in facial manipulations -in particular, automatic generation of facial attributes and expressions. Fig. 1(b) shows one such recent example where various facial attributes such as hair, gender, age and skin color, and expressions such as anger, happiness and fear are generated on faces of celebrities [2].
While the visual results are promising, the GAN based techniques alter the statistics of pixels in the images that they generate. Hence, methods that look for deviations from natural image statistics could be effective in detecting GAN generated fake images. These methods have been well studied in the field of steganalysis which aims to detect the presence of hidden data in digital images. One such method is based on analyzing co-occurrences of pixels by computing a co-occurrence matrix. Traditionally, this method uses hand crafted features computed on the co-occurrence matrix and a machine learning classifier such as support vector machines determines if a message is hidden in the image [5,6]. Other techniques involve calculating image residuals or passing the image through different filters before computing the co-occurrence matrix [7,8,9].
Inspired by steganalysis and natural image statistics, we propose a novel method to identify GAN generated images using a combination of pixel co-occurrence matrices and deep learning. Here we pass the co-occurrence matrices directly through a deep learning framework and allow the network to learn important features of the co-occurrence matrices. We also avoid computation of residuals or passing an image through various filters, but rather compute the co-occurrence matrices on the image pix-(a) Images generated using CycleGAN [1] (b) Images generated using StarGAN [2] Figure 1: Examples of images that have been generated using GANs. els itself. Experimental results on two diverse and challenging datasets generated using GAN based methods show that our approach is promising and generalizes well when the GAN model is not known during training.

Related Work
Since the seminal work on GANs [3], there have been several hundreds of papers on using GANs to generate images. These works focus on generating images of high perceptual quality [10,11,12,13,14,15,4], image-to-image translations [13,16,1], domain transfer [17,18], super-resolution [19], image synthesis and completion [20,21,22], and generation of facial attributes and expressions [23,24,18,2]. Several methods have been proposed in the area of image forensics over the past years [25,26,27,28,29]. Recent approaches have focused on applying deep learning based methods to detect tampered images [30,31,32,33,34,9,35] The detection of GAN images is a new area in image forensics and there are very few papers in this area [36,37,38,39,40,41,42,43,44,45]. Related fields also include detection of computer generated (CG) images [46,47,48,49]. The most relevant work is a recent paper [36] on detecting GAN based image-toimage translation generated using cycleGAN [1]. Here the authors compare various existing methods to identify cycleGAN images from normal ones. The top results they obtained using a combination of residual features [50,9] and deep learning [51]. Similar to [36], the authors in [38] compute the residuals of high pass filtered images and then extract co-occurrence matrices on these residuals, which are then concatenated to form a feature vector that can distinguish real from fake GAN images. In contrast to these approaches, our approach does not need any image resid-uals to be computed. Rather, our method directly computes cooccurrence matrices on the three color channels which are then passed through a deep convolutional neural network (CNN) to learn a model that can detect fake GAN generated images.

Methodology
To detect GAN images, we compute co-occurrence matrices on the RGB channels of an image. Co-occurrence matrices have been previously used in steganalysis to identify images that have data hidden in them [5,6,7,8] and in image forensics to detect or localize tampered images [50,9]. In prior works, cooccurrence matrices are usually computed on image residuals by passing the image through many filters and then obtaining the difference. Sometimes features or statistics are also computed on the matrices and then a classifier is trained on these features to classify data hidden or tampered images [5].
However, in this paper, we compute co-occurrence matrices directly on the image pixels on each of the red, green and blue channels and pass them through a convolutional neural network, thereby allowing the network to learn important features from the co-occurrence matrices. An overview of our approach is shown in Fig. 2. Specifically, the first step is to compute the co-occurrence matrices on the RGB channels to obtain a 3x256x256 tensor. This tensor is then passed through a multi-layer deep convolutional neural network: conv layer with 32 3x3 convs + ReLu layer + conv layer with 32 5x5 convs + max pooling layer + conv layer with 64 3x3 convs + ReLu layer + conv layer with 64 5x5 convs + max pooling layer + conv layer with 128 3x3 convs + ReLu layer + conv layer with 128 5x5 convs + max pooling layer + 256 dense layer + 256 dense layer + sigmoid layer. A variant of adaptive

Experiments
We evaluate our method on two diverse and challenging datasets which contain GAN generated images such as image-toimage translation, style transfer, facial attributes and expressions.

Datasets
CycleGAN dataset: This dataset contains unpaired image-toimage translations of various objects and scenes such as horsesto-zebras, summer-to-winter, images to paintings (Monet, Van Gough), style transfer such as labels to facades, and others that were generated using a cycle-consistent GAN framework [1]. We followed the instructions provided by the authors as detailed in https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix, and obtained 36,302 images (18, [52] of celebrity faces and the remaining 17,991 images were GAN generated images with 5 varying facial attributes such as black hair, blond hair, brown hair, gender change, aged and 4 combinations of the same. We followed the instructions in https://github.com/yunjey/stargan to generate the images.

Evaluation
We first evaluate our approach on two datasets separately and then perform cross evaluation on the two datasets (one dataset as training and other as testing) to see the generalizability of our approach. For both datasets, 50% of the data is used for training, 25% for validation and 25% for testing. We train the network for 50 epochs with a batch size of 40 and use a variant of adaptive stochastic gradient as optimizer. Fig. 3(a,b) and Fig. 3(c,d) show the model accuracy and loss on cycleGAN dataset and Star-GAN dataset, respectively. We obtained a high training and validation accuracy of 99.90% and 99.40% on cycleGAN dataset, and 99.43% and 99.39% on StarGAN dataset respectively. We 1 We thank the authors for providing the dataset distribution

Generalizability
Next, we evaluate the generalizability of our approach by training on one dataset and testing on the other. First we train on all the images in the cycleGAN dataset (35,302 images) and test the model on all images of the StarGAN dataset (19,990) images, and then we reverse the experiment where we train on StarGAN and test on cycleGAN. We train the network till 50 epochs and report on the model that gave the highest accuracy. As shown in Tab. 1, our method still maintains a high accuracy even across diverse datasets. The model trained on cycleGAN dataset has a higher accuracy of 99.45% in comparison with the model trained on StarGAN dataset which got 93.42%. The lower accuracy for the model trained on StarGAN dataset could be because of the non-uniform distribution of class samples in the StarGAN dataset, and due to the diverse image sources/categories in the cycleGAN dataset.

Comparison with State-of-the-art
We compare our approach with the results presented in [36].
Here the authors conduct a study on the detection of images manipulated by GAN-based image-to-image translation on the cycleGAN dataset. For evaluation, they adopt a leave-onemanipulation-out strategy on the categories in the cycleGAN dataset, where at each iteration images belonging to one category are set aside for validation and the images from other categories are used for training. The methods evaluated are based on steganalysis, generic image manipulations, detection of computer graphics, a GAN discriminator used in the cycleGAN paper, and generic deep learning architecture pretrained on ImageNet [53], but fine tuned to the cycleGAN dataset. Among these the top preforming ones were from steganalysis [8,50] based on extracting features from high-pass residual images, a deep neural network designed to extract residual features [9] (denoted by Coz-zolino2017) and XceptionNet [51] deep neural network trained   on ImageNet but fine-tuned to this dataset. We report the results as mentioned in the paper only from these three methods and compare with our approach.
Results on original images: Here we consider the images generated from the cycleGAN dataset as it is and do not perform any postprocessing on the images. Tab. 2 summarizes the results of our proposed approach along with with the three top performing approaches in [36]. On average our method outperformed other methods and was able to achieve an accuracy of 97.84. On most categories, our approach was better than or on-par with the other top methods. The only categories where our method performed poorly were 'cityscapes' and 'facades'. These could be because the original images in these categories were JPEG compressed which could have affected the classification accuracy. In the next section, we study the effect of compression on our method.

Effect of JPEG compression:
In [36], the authors investigated the sensitivity of their methods on compression. Using a compression method similar to Twitter, they trained their detection methods on original uncompressed images and tested on JPEG compressed images. The objective of this study was to test the robustness of the detection techniques when images are posted in social networks such as Twitter. In the second scenario, they train and test on the JPEG compressed images. We performed both of these experiments on the cycleGAN dataset. Since we are not aware of the exact JPEG quantization tables used in Twitter, our approach was similar but we tested on three different JPEG quality factors (QF): 95, 85 and 75. We used 50% of the data for training, 25% for validation and 25% for testing. The results are reported on the 25% testing data of the cycleGAN dataset (9,076 images). As shown in Tab. 3, the accuracy progressively drops as the QF decreases from 95-75, when trained on the original im-ages. But when the JPEG compressed images are used for training, the accuracy shows a substantial increase. Even at a QF of 75, the accuracy is still 87.31%. This is also consistent with the results reported in [36], where they report close to a 10% drop in accuracy on Twitter-like compressed images.

Conclusions
In this paper, we proposed a novel method to detect GAN generated fake images using a combination of pixel co-occurrence matrices and deep learning. Co-occurrence matrices are computed on the color channels of an image and then trained using a deep convolutional neural network to distinguish GAN generated fake images from real ones. Experiments on two diverse GAN datasets show that our approach is both effective and generalizable. In future, we will consider localizing the manipulated pixels in GAN generated fake images. . Amit K. Roy-Chowdhury received the Bachelors degree in Electrical Engineering from Jadavpur University, Calcutta, India, the Masters degree in Systems Science and Automation from the Indian Institute of Science, Bangalore, India, and the Ph.D. degree in Electrical and Computer Engineering from the University of Maryland, College Park. He is a Professor of Electrical and Computer Engineering and a Cooperating Faculty in the Department of Computer Science and Engineering, University of California, Riverside. His broad research interests include computer vision, image processing, and vision-based statistical learning, with applications in cyber-physical, autonomous and intelligent systems. He is a coauthor of two books: Camera Networks: The Acquisition and Analysis of Videos over Wide Areas, and Recognition of Humans and Their Activities Using Video. He is the editor of the book Distributed Video Sensor Networks. He has been on the organizing and program committees of multiple computer vision and image processing conferences and is serving on the editorial boards of multiple journals. He is a Fellow of the IEEE and IAPR.