All Projects → NicoRahm → CGvsPhoto

NicoRahm / CGvsPhoto

Licence: MIT license
Computer Graphics vs Real Photographic Images : A Deep-learning approach

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to CGvsPhoto

NIvsCG-keras
Distinguishing Between Natural and Computer-Generated Images Using Convolutional Neural Networks in Keras.
Stars: ✭ 20 (-16.67%)
Mutual labels:  computer-graphics, image-forensics
favorite-research-papers
Listing my favorite research papers 📝 from different fields as I read them.
Stars: ✭ 12 (-50%)
Mutual labels:  image-classification, research-paper
minionn
Privacy -preserving Neural Networks
Stars: ✭ 58 (+141.67%)
Mutual labels:  research-paper
image-sorter2
One-click image sorting/labelling script
Stars: ✭ 65 (+170.83%)
Mutual labels:  image-classification
MNIST
Handwritten digit recognizer using a feed-forward neural network and the MNIST dataset of 70,000 human-labeled handwritten digits.
Stars: ✭ 28 (+16.67%)
Mutual labels:  image-classification
goexif2
MAINTAINER WANTED -- Decode embedded EXIF meta data from image files written in Pure Golang
Stars: ✭ 35 (+45.83%)
Mutual labels:  image-classification
AlphaTree-graphic-deep-neural-network
AI Roadmap:机器学习(Machine Learning)、深度学习(Deep Learning)、对抗神经网络(GAN),图神经网络(GNN),NLP,大数据相关的发展路书(roadmap), 并附海量源码(python,pytorch)带大家消化基本知识点,突破面试,完成从新手到合格工程师的跨越,其中深度学习相关论文附有tensorflow caffe官方源码,应用部分含推荐算法和知识图谱
Stars: ✭ 2,221 (+9154.17%)
Mutual labels:  image-classification
meta-st-stm32mpu-ai
This repository contains the OpenEmbedded meta layer to install AI frameworks and tools for the STM32MP1
Stars: ✭ 32 (+33.33%)
Mutual labels:  image-classification
TFLite-Android-Helper
TensorFlow Lite Helper for Android to help getting started with TesnorFlow.
Stars: ✭ 25 (+4.17%)
Mutual labels:  image-classification
racket-vulkan
Racket integration with all things Vulkan 💥
Stars: ✭ 40 (+66.67%)
Mutual labels:  computer-graphics
SynergyNet
3DV 2021: Synergy between 3DMM and 3D Landmarks for Accurate 3D Facial Geometry
Stars: ✭ 179 (+645.83%)
Mutual labels:  computer-graphics
deep-learning
Projects include the application of transfer learning to build a convolutional neural network (CNN) that identifies the artist of a painting, the building of predictive models for Bitcoin price data using Long Short-Term Memory recurrent neural networks (LSTMs) and a tutorial explaining how to build two types of neural network using as input the…
Stars: ✭ 43 (+79.17%)
Mutual labels:  image-classification
-
图形学书单
Stars: ✭ 84 (+250%)
Mutual labels:  computer-graphics
Teapong
A two-player game for fans of Pong and the Utah teapot!
Stars: ✭ 24 (+0%)
Mutual labels:  computer-graphics
creative-coding-notebooks
🎨 An authorial collection of fundamental recipes on Creative Coding and Recreational Programming.
Stars: ✭ 17 (-29.17%)
Mutual labels:  computer-graphics
Metu-CENG
All the homeworks, studies and projects I've done at Metu-CENG
Stars: ✭ 32 (+33.33%)
Mutual labels:  computer-graphics
sioyek
Sioyek is a PDF viewer designed for reading research papers and technical books.
Stars: ✭ 3,890 (+16108.33%)
Mutual labels:  research-paper
ros2-tensorflow
ROS2 nodes for computer vision tasks in Tensorflow
Stars: ✭ 41 (+70.83%)
Mutual labels:  image-classification
Shader-Playgrounds
A WebGL shaders editor for beginners and otherwise.
Stars: ✭ 28 (+16.67%)
Mutual labels:  computer-graphics
Plant AI
Performing Leaf Image classification for Recognition of Plant Diseases using various types of CNN Architecture, For detection of Diseased Leaf and thus helping the increase in crop yield.
Stars: ✭ 36 (+50%)
Mutual labels:  image-classification

Computer Graphics vs Real Photographic Images : A Deep-learning approach

CGvsPhoto implements a method for computer graphics detection using Convolutional Neural Networks with TensorFlow back-end. The package contains methods for extracting patches from computer graphics and real images, training a CNN with a custom statistical layer, testing this model, comparing with a state of the art method, visualizing probability maps, etc. See the paper corresponding to this model here.

splicing

Dataset

The dataset used for testing our method is composed of 1800 real photographs and 1800 Video-game images. The photographs were randomly taken from the Raise Database and converted to JPEG format (compression rate 95%). The names of the images used during our experiments for each set (training, testing and validation) are available on the corresponding .csv files in the data directory.

The Video-game images were downloaded from the Level-design reference Database and cropped to remove in-game informations. They were extracted from 5 of the most photorealistic video-games: The Witcher 3, Battlefield 4, Battlefield Bad Company 2, Grand Theft Auto 5 and Uncharted 4. To download the preprocessed images, follow this link.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for testing purposes.

Prerequisites

Installing

Simply install this package with pip3 :

$ pip3 install CGvsPhoto

You can also clone the repository into your favorite directory.

$ git clone https://github.com/NicoRahm/CGvsPhoto

Then, install the package using :

$ cd CGvsPhoto/
$ pip3 install .

To run your first test, there is one more thing to set up:

  • Create a file named config.ini in your execution directory (the directory containing your scripts) to store the different configurations of your environment. The format is the following :
[Name of the configuration]
dir_ckpt = /path/to/save/trained/weights/
dir_summaries = /path/to/save/summaries
dir_visualization = /path/to/save visualizations

An example file is given in the examples directory.

Database format

Your database must follow this organization :

Database/
    test/
        CGG/
        Real/
    train/
        CGG/
        Real/
    validation/
        CGG/
        Real/

You can create it manually or use the function construct_DB.

Some simple examples

To get started, you can run simple scripts from the examples directory. Do not forget to set up the config.ini file correctly as described above and to modify the paths to data.

How to use

This section explains basic uses of this code. We describe a step by step procedure to evaluate our model on your database.

Formatting the database

As our code uses a special format for the database, the first thing you need to do is to create a suited structure for the data. You can do this manually but we give a piece of code to do it automatically which may prevent bad surprises… It creates validation, training and testing directories and put a certain number of images per class in it (same number of image for each class) To do so, you just need to have CG and PG images in two different directories and choose another directory to store the formatted database. Then you can just use the construct_DB method :

from CGvsPhoto import construct_DB

path_CG = '/path/to/CG'
path_PG = '/path/to/PG'
path_export = 'path/to/export/database'

construct_DB(source_real = path_PG, source_CG = path_CG,
             target_dir = path_export, nb_per_class = 1000,
             validation_proportion = 0.1, test_proportion = 0.2)

You can choose the total number of images per class and the proportion of images to put in each directory.

Creating the patches database

Our implementation computes local patch classification before aggregating the results for full-size images. So, to train the single-image classifier, a patch database must be created. To this end, use the Database_loader class :

from CGvsPhoto import Database_loader

path_source = 'path/to/source/database'
path_export = 'path/to/export/patches'
size_patch = 100

data = Database_loader(path_source, image_size = size_patch,
                     only_green=True)

# export a patch database
data.export_database(path_export,
                     nb_train = 40000,
                     nb_test = 4000,
                     nb_validation = 2000)

You can choose the patch size (100x100 pixels in our initial implementation) and the number of patches to put in each directory (with 50/50 distribution between each class).

Note that supported image extensions are [“.jpg”,“.gif”,“.png”,“.tga”,“.tif”, “.JPG”, “.jpeg”]

Creating a model

Now comes the fun part! In order to create your own model, you just have to call the Model class. For example :

from CGvsPhoto import Model

model = Model(database_path 'Database/My_Patch_Data', image_size = 100,
              config = 'Config1', filters = [32, 64],
              feature_extractor = 'Stats', batch_size = 50)

You can specify the number of output filtered images for each layer with the parameter filters and the feature extraction scheme (between ‘Hist’ and ‘Stats’). You also need to give the path to the patch database.

Warning : The database must contain images with the same image_size as specified in parameter image_size.

Training a classifier

Now, to train this model, use the train function specifying the number of training/validation/testing batches:

model.train(nb_train_batch = 15000,
            nb_test_batch = 80,
            nb_validation_batch = 40)

This will train a model and save the weights and a bunch of summaries in correspondant directories (you specify the name of the run at the begining of the procedure). You can also load a pre-trained model and continue the training (be careful though to load a model which structure corresponds to the one you are trying to train).

At the end of training, the model’s accuracy is evaluated on the patches testing set.

Testing

Now that you have trained a model, you can load it and test it on full-size images, using the test_total_images function :

test_data_path = '/Database/My_Data/test/'
clf.test_total_images(test_data_path = test_data_path,
                      nb_images = 720, decision_rule = 'weighted_vote')

Your test directory must contain two sub-directories : CGG and Real. Before testing, the console will ask you the name of the weight file to load. It must be in the default checkpoint directory and you should inidcate the .ckpt file. You can specify the number of images you want to process and the aggregation scheme between ‘weighted_vote’ and ‘majority_vote’ (even if ‘weighted_vote’ is in general more efficient).

Reproducing the results

The architecture used in our article [Distinguishing Computer Graphics from Natural Images Using Convolution Neural Networks, WIFS, 2017] can be reproduced by using the default parameters of the Model class. The weights used for this model are available as TensorFlow checkpoints in the folder /weights: use "Stats_15000_run_14800.ckpt"

Authors

Nicolas Rahmouni - GitHub

Vincent Nozick - Website

References

Rahmouni, N., Nozick, V., Yamagishi, J., & Echizen, I. (2017, December). Distinguishing Computer Graphics from Natural Images Using Convolution Neural Networks. In IEEE Workshop on Information Forensics and Security, WIFS 2017.

This research was carried out while the authors stayed at the National Institute of Informatics, Japan

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].