Detecting GAN generated Fake Images using Co-occurrence Matrices
Lakshmanan Nataraj, Tajuddin Manhar Mohammed, Shivkumar Chandrasekaran, Arjuna Flenner, Jawadul H. Bappy, Amit K. Roy-Chowdhury, B. S. Manjunath
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) 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 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 , augmenting faces with CG facial attributes , and seamless transfer of texture between images , 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 . 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 .
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 . Other techniques involve calculating image residuals or passing the image through different filters before computing the co-occurrence matrix .
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 pixels 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 , there have been several hundreds of papers on using GANs to generate images. These works focus on generating images of high perceptual quality , image-to-image translations , domain transfer , super-resolution , image synthesis and completion , and generation of facial attributes and expressions . Several methods have been proposed in the area of image forensics over the past years . Recent approaches have focused on applying deep learning based methods to detect tampered images
The detection of GAN images is a new area in image forensics and there are very few papers in this area . Related fields also include detection of computer generated (CG) images . The most relevant work is a recent paper on detecting GAN based image-to-image translation generated using cycleGAN . 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 and deep learning . Similar to , the authors in 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 residuals to be computed. Rather, our method directly computes co-occurrence 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 and in image forensics to detect or localize tampered images . In prior works, co-occurrence 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 .
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 stochastic gradient descent is used as the optimizer.
Experiments
We evaluate our method on two diverse and challenging datasets which contain GAN generated images such as image-to-image translation, style transfer, facial attributes and expressions.
CycleGAN dataset: This dataset contains unpaired image-to-image translations of various objects and scenes such as horses-to-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 . 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,151 GAN and 18,151 non-GAN images). The distribution of GAN images are as follows: apple2orange (2014), horse2zebra (2401), summer2winter (2193), cityscapes (2975), facades (400), map2sat (1096), Ukiyoe (1500), Van Gogh (1500), Cezanne (1500), Monet (2752). We obtained this distribution from the authors of We thank the authors for providing the dataset distribution and we compare our approach with their results in the Experiments section.
StarGAN dataset: This dataset consists of 19,990 images of which 1,999 were from faces taken from the celebA dataset 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 StarGAN 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 then evaluated the model on the held-out test sets and obtained a testing accuracy of 99.71% on the cycleGAN dataset and 99.37% on the StarGAN dataset.
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 . 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-one-manipulation-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 , but fine tuned to the cycleGAN dataset. Among these the top preforming ones were from steganalysis based on extracting features from high-pass residual images, a deep neural network designed to extract residual features (denoted by Cozzolino2017) and XceptionNet 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 . 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 , 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 images. 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 , 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.
Acknowledgments
This research was developed with funding from the Defense Advanced Research Projects Agency (DARPA). The views, opinions and/or findings expressed are those of the author and should not be interpreted as representing the official views or policies of the Department of Defense or the U.S. Government. The paper is approved for public release, distribution unlimited.
References
Author Biography
Lakshmanan Nataraj received his B.E degree in Electronics and Communications Engineering from Sri Venkateswara College of Engineering (affiliated to Anna University) in 2007, and the Ph.D. degree in the Electrical and Computer Engineering from the University of California, Santa Barbara in 2015. He is currently a Senior Research Staff Member at Mayachitra Inc., Santa Barbara, CA, where he leads research projects on malware detection and media forensics. His research interests include multimedia security, malware detection and image forensics.
Tajuddin Manhar Mohammed received his B.Tech (Hons.) degree in Electrical Engineering from Indian Institute of Technology (IIT), Hyderabad, India in 2015 and his M.S. degree in Electrical and Computer Engineering from University of California Santa Barbara (UCSB), Santa Barbara, CA in 2016. After obtaining his Masters degree, he obtained a job as a Research Staff Member for Mayachitra Inc., Santa Barbara, CA. His recent research efforts include developing deep learning and computer vision techniques for image forensics and cyber security.
B. S. Manjunath (S’88–M’91–SM’01–F’05) received the Ph.D. degree in electrical engineering from the University of Southern California, Los Angeles, CA, USA, in 1991. He is currently a Distinguished Professor of Electrical and Computer Engineering at the University of California at Santa Barbara, where he directs the Center for Multimodal Big Data Science and Healthcare. He has authored or coauthored about 300 peer-reviewed articles and served as an Associate Editor for the IEEE Transactions on Image Processing, the IEEE Transactions on Pattern Analysis and Machine Intelligence, the IEEE Transactions on Multimedia, the IEEE Transactions on Information Forensics and Security, and the IEEE Signal Processing Letters. His research interests include image processing, machine learning, computer vision, and media forensics. He is a fellow of IEEE and ACM.
Shivkumar Chandrasekaran received his M.Sc. (Hons.) degree in physics from the Birla Institute of Technology and Science (BITS), Pilani, India, in 1987, and his Ph.D. degree in Computer Science from Yale University, New Haven, CT, in 1994. He was a Visiting Instructor at North Carolina State University, Raleigh, in the Mathematics Department, before joining the Electrical and Computer Engineering Department, University of California, Santa Barbara, where he is currently a Professor. His research interests are in Computational Mathematics
Arjuna Flenner received his Ph.D. in Physics at the University of Missouri-Columbia located in Columbia MO in the year 2004. His major emphasis was mathematical Physics. After obtaining his Ph.D., Arjuna Flenner obtained a job as a research physicist for NAVAIR at China Lake CA. He won the 2013 Dr. Delores M. Etter Navy Scientist and Engineer award for his work on Machine Learning.
Jawadul H. Bappy received the B.S. degree in Electrical and Electronic Engineering from the Bangladesh University of Engineering and Technology, Dhaka in 2012. He received his Ph.D. in Electrical and Computer Engineering from the University of California, Riverside in 2018. He is currently working as a scientist at JD.Com in Mountain View, CA. His main research interest includes media forensics, deep generative models, and advanced machine learning techniques for real-life applications.
Amit K. Roy-Chowdhury received the Bachelor’s degree in Electrical Engineering from Jadavpur University, Calcutta, India, the Master’s 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.