{ "info": { "author": "Nicolas Rahmouni", "author_email": "nicolas.rahmouni@polytechnique.edu", "bugtrack_url": null, "classifiers": [], "description": "Computer Graphics vs Real Photographic Images : A Deep-learning approach\n========================================================================\n\n.. image:: https://badge.fury.io/py/CGvsPhoto.svg\n :target: https://badge.fury.io/py/CGvsPhoto\n \n**CGvsPhoto** implements a method for computer graphics detection using\nConvolutional Neural Networks with TensorFlow back-end. The package\ncontains methods for extracting patches from computer graphics and real\nimages, training a CNN with a custom statistical layer, testing this\nmodel, comparing with a `state of the art method`_, visualizing\nprobability maps, etc.\n\n.. figure:: https://user-images.githubusercontent.com/17125992/26917538-9d918318-4c69-11e7-8c6f-f865b3c5f063.png\n :alt: splicing\n\n\nGetting Started\n---------------\n\nThese instructions will get you a copy of the project up and running on\nyour local machine for testing purposes.\n\nPrerequisites\n~~~~~~~~~~~~~\n\n- Python 3.6+\n- Numpy 1.6.1+\n- Scikit-learn 0.18.1+\n- TensorFlow 1.0.1+ (https://github.com/tensorflow/tensorflow)\n- Pillow 3.1.2+\n- Matplotlib 1.3.1+\n\nInstalling\n~~~~~~~~~~\n\nSimply install this package with pip3 : \n::\n\n $ pip3 install CGvsPhoto\n\nYou can also clone the repository into your favorite directory.\n\n::\n\n $ git clone https://github.com/NicoRahm/CGvsPhoto\n\nThen, install the package using :\n\n::\n\n $ cd CGvsPhoto/\n $ pip3 install .\n\nTo run your first test, there is one more thing to set up:\n\n- 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 :\n\n::\n\n [Name of the configuration]\n dir_ckpt = /path/to/save/trained/weights/\n dir_summaries = /path/to/save/summaries\n dir_visualization = /path/to/save visualizations\n\nAn example file is given in the examples directory.\n\nDatabase format\n~~~~~~~~~~~~~~~\n\nYour database must follow this organization :\n\n::\n\n Database/\n test/\n CGG/\n Real/\n train/\n CGG/\n Real/\n validation/ \n CGG/\n Real/\n\nYou can create it manually or use the function construct\\_DB.\n\nSome simple examples\n~~~~~~~~~~~~~~~~~~~~\n\nTo get started, you can run simple scripts from the examples directory.\nDo not forget to **set up the config.ini file** correctly as described\nabove and to modify the paths to data.\n\n- `create\\_DB.py`_ will create a formated database for future tests.\n- `create\\_patches\\_splicing.py`_ will create a patches database for\n training single-image classifier and a splicing database to test our\n models.\n- `test\\_pipeline.py`_ trains a neural network to classify image\n patches and then evaluate it.\n- `test\\_splicing.py`_ tests a model on spliced images.\n\nHow to use\n----------\n\nThis section explains basic uses of this code. We describe a step by\nstep procedure to evaluate our model on your database.\n\nFormatting the database\n~~~~~~~~~~~~~~~~~~~~~~~\n\nAs our code uses a special format for the database, the first thing you\nneed to do is to create a suited structure for the data. You can do this\nmanually but we give a piece of code to do it automatically which may\nprevent bad surprises\u2026 It creates validation, training and testing\ndirectories and put a certain number of images per class in it (same\nnumber of image for each class) To do so, you just need to have CG and\nPG images in two different directories and choose another directory to\nstore the formatted database. Then you can just use the *construct\\_DB*\nmethod :\n\n.. code:: python\n\n from CGvsPhoto import construct_DB\n\n path_CG = '/path/to/CG'\n path_PG = '/path/to/PG'\n path_export = 'path/to/export/database'\n\n construct_DB(source_real = path_PG, source_CG = path_CG,\n target_dir = path_export, nb_per_class = 1000,\n validation_proportion = 0.1, test_proportion = 0.2)\n\nYou can choose the total number of images per class and the proportion\nof images to put in each directory.\n\nCreating the patches database\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nOur implementation computes local patch classification before\naggregating the results for full-size images. So, to train the\nsingle-image classifier, a patch database must be created. To this end,\nuse the *Database\\_loader* class :\n\n.. code:: python\n\n from CGvsPhoto import Database_loader\n\n path_source = 'path/to/source/database'\n path_export = 'path/to/export/patches'\n size_patch = 100\n\n data = Database_loader(path_source, image_size = size_patch, \n only_green=True)\n\n # export a patch database \n data.export_database(path_export, \n nb_train = 40000, \n nb_test = 4000, \n nb_validation = 2000)\n\nYou can choose the patch size (100x100 pixels in our initial\nimplementation) and the number of patches to put in each directory (with\n50/50 distribution between each class).\n\nNote that supported image extensions are\n[\u201c.jpg\u201d,\u201c.gif\u201d,\u201c.png\u201d,\u201c.tga\u201d,\u201c.tif\u201d, \u201c.JPG\u201d, \u201c.jpeg\u201d]\n\nCreating a model\n~~~~~~~~~~~~~~~~\n\nNow comes the fun part! In order to create your own model, you just have\nto call the *Model* class. For example :\n\n.. code:: python\n\n from CGvsPhoto import Model\n\n model = Model(database_path 'Database/My_Patch_Data', image_size = 100,\n config = 'Config1', filters = [32, 64], \n feature_extractor = 'Stats', batch_size = 50)\n\nYou can specify the number of output filtered images for each layer with\nthe parameter ``filters`` and the feature extraction scheme (between\n\u2018Hist\u2019 and \u2018Stats\u2019). You also need to give the path to the patch\ndatabase.\n\nWarning : The database must contain images with the same image\\_size as\nspecified in parameter image\\_size.\n\nTraining a classifier\n~~~~~~~~~~~~~~~~~~~~~\n\nNow, to train this model, use the *train* function specifying the number\nof training/validation/testing batches:\n\n.. code:: python\n\n model.train(nb_train_batch = 15000,\n nb_test_batch = 80, \n nb_validation_batch = 40)\n \nThis will train a model and save the weights and a bunch of summaries in\ncorrespondant directories (you specify the name of the run at the\nbegining of the procedure). You can also load a pre-trained model and\ncontinue the training (be careful though to load a model which structure\ncorresponds to the one you are trying to train).\n\nAt the end of training, the model\u2019s accuracy is evaluated on the patches\ntesting set.\n\nTesting\n~~~~~~~\n\nNow that you have trained a model, you can load it and test it on\nfull-size images, using the *test\\_total\\_images* function :\n\n.. code:: python\n\n test_data_path = '/Database/My_Data/test/'\n clf.test_total_images(test_data_path = test_data_path,\n nb_images = 720, decision_rule = 'weighted_vote')\n\nYour test directory must contain two sub-directories : CGG and Real.\nBefore testing, the console will ask you the name of the weight file to\nload. It must be in the default checkpoint directory and you should\ninidcate the .ckpt file. You can specify the number of images you want\nto process and the aggregation scheme between \u2018weighted\\_vote\u2019 and\n\u2018majority\\_vote\u2019 (even if \u2018weighted\\_vote\u2019 is in general more\nefficient).\n\nAuthors\n-------\n\n**Nicolas Rahmouni** - `NicoRahm`_\n\n**Vincent Nozick**\n\n\n.. _NicoRahm: https://github.com/NicoRahm\n.. _state of the art method: http://ieeexplore.ieee.org/abstract/document/6115849/\n.. _create\\_DB.py: examples/create_DB.py\n.. _create\\_patches\\_splicing.py: examples/create_patches_splicing.py\n.. _test\\_pipeline.py: examples/test_pipeline.py\n.. _test\\_splicing.py: examples/test_splicing.py", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/NicoRahm/CGvsPhoto", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "CGvsPhoto", "package_url": "https://pypi.org/project/CGvsPhoto/", "platform": "", "project_url": "https://pypi.org/project/CGvsPhoto/", "project_urls": { "Homepage": "https://github.com/NicoRahm/CGvsPhoto" }, "release_url": "https://pypi.org/project/CGvsPhoto/0.0.3/", "requires_dist": null, "requires_python": "", "summary": "A deep-learning method for distinguishing computer graphics from real photogrphic images", "version": "0.0.3" }, "last_serial": 3253770, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "7514d401eef4e263763610099ca561b9", "sha256": "fcfc04dece0aa0e6f358dda540d2dc1153946f10f4eeb647f50db1ec4b1b2b10" }, "downloads": -1, "filename": "CGvsPhoto-0.0.1.tar.gz", "has_sig": false, "md5_digest": "7514d401eef4e263763610099ca561b9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 24981, "upload_time": "2017-06-09T08:07:31", "url": "https://files.pythonhosted.org/packages/c2/ac/10586d615ac7048a572093d10487bab8ad9993b23ba30e1385d9e8d9fabc/CGvsPhoto-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "e8dc3d5fcae0e627f47d9f192fd9ee9b", "sha256": "6ccea5cc7c92341f00db8a2ee5180b229f0960a1df4164e4b9d61ea8b8b9b993" }, "downloads": -1, "filename": "CGvsPhoto-0.0.2.tar.gz", "has_sig": false, "md5_digest": "e8dc3d5fcae0e627f47d9f192fd9ee9b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 24976, "upload_time": "2017-06-09T08:34:10", "url": "https://files.pythonhosted.org/packages/7c/28/0f797e91a7f87fd3256436284fbd144e9fc613955919a480c7135fb5c9d5/CGvsPhoto-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "f1ee7c11dce5b8033f0ec12c45f09162", "sha256": "9f018c9dcc08b524f4e6440f12577f142bb92b8cd5b3e5de757f47522a077c06" }, "downloads": -1, "filename": "CGvsPhoto-0.0.3.tar.gz", "has_sig": false, "md5_digest": "f1ee7c11dce5b8033f0ec12c45f09162", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 26543, "upload_time": "2017-10-16T14:20:55", "url": "https://files.pythonhosted.org/packages/19/df/a379c32e53911eba651f672de20b865854103a8b43391117841e659ed29a/CGvsPhoto-0.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f1ee7c11dce5b8033f0ec12c45f09162", "sha256": "9f018c9dcc08b524f4e6440f12577f142bb92b8cd5b3e5de757f47522a077c06" }, "downloads": -1, "filename": "CGvsPhoto-0.0.3.tar.gz", "has_sig": false, "md5_digest": "f1ee7c11dce5b8033f0ec12c45f09162", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 26543, "upload_time": "2017-10-16T14:20:55", "url": "https://files.pythonhosted.org/packages/19/df/a379c32e53911eba651f672de20b865854103a8b43391117841e659ed29a/CGvsPhoto-0.0.3.tar.gz" } ] }