├── .gitignore ├── LICENSE ├── README.md ├── build.xml ├── lib ├── commons-io-2.5.jar ├── ij.jar ├── jfoenix.jar ├── logback-classic-1.1.7.jar ├── logback-core-1.1.7.jar ├── metadata-extractor-2.9.1.jar ├── neuroph-core-2.92.jar ├── neuroph-imgrec-2.92.jar ├── slf4j-api-1.7.21.jar └── xmpcore-5.1.2.jar ├── manifest.mf ├── nbproject ├── UPDATED.TXT ├── build-impl.xml ├── configs │ ├── Run_as_WebStart.properties │ └── Run_in_Browser.properties ├── genfiles.properties ├── jfx-impl.xml ├── jfx-impl_backup.xml ├── jfx-impl_backup_1.xml ├── jfx-impl_backup_2.xml ├── jfx-impl_backup_3.xml ├── jfx-impl_backup_4.xml ├── jfx-impl_backup_5.xml ├── jfx-impl_backup_6.xml ├── project.properties └── project.xml ├── nnet ├── CNN2.nnet ├── CNN_V1.0.nnet ├── CNN_V2.0.nnet ├── CNN_V3.0.nnet └── MLPV2.0.nnet └── src ├── com └── gc │ └── fakeimagedetection │ ├── core │ ├── FIDNetworkAnalyser.java │ ├── FIDNetworkTrainer.java │ ├── FIDPreprocessor.java │ ├── constants │ │ └── ConstantObjects.java │ ├── errorlevelanalysis │ │ ├── ErrorLevelAnalyzer.java │ │ ├── FIDErrorLevelAnalysis.java │ │ └── ImageStandardizer.java │ ├── listener │ │ ├── BatchImageTestingListener.java │ │ ├── BatchImageTrainingListener.java │ │ ├── ErrorLevelAnalysisListener.java │ │ ├── ErrorLevelAnalysisUpdateListener.java │ │ ├── NeuralNetworkCreationCompleteListener.java │ │ ├── NeuralnetProcessorListener.java │ │ └── ThreadCompleteListener.java │ ├── metadata │ │ └── MetadataProcessor.java │ ├── multithread │ │ └── NotifyingThread.java │ ├── neuralnet │ │ └── MLPNetworkMaker.java │ ├── processor │ │ └── NeuralNetProcessor.java │ ├── tester │ │ └── BatchImageTestProcessor.java │ └── trainer │ │ ├── BatchImageTrainer.java │ │ └── SingleImageTrainer.java │ └── ui │ ├── BatchImageTester.java │ ├── ELABatchImageProcessor.java │ ├── Main.java │ ├── NeuralNetCreator.java │ ├── SingleImageCheck.java │ ├── TrainerMain.java │ ├── alert │ ├── Calert.java │ └── CommonUtil.java │ └── controllers │ ├── BatchImageProcessorController.java │ ├── BatchImageTesterController.java │ ├── LaunchScreeenController.java │ ├── MetadataDisplayController.java │ ├── MetadataResultController.java │ ├── NetworkcreatorController.java │ ├── NeuralnetInterfaceController.java │ ├── SingleImageAnalyzerController.java │ └── TrainingInterfaceController.java └── resources ├── fxml ├── batchimageprocessor.fxml ├── batchimagetester.fxml ├── home.png ├── infinity.png ├── launch.fxml ├── metadatadisplay.fxml ├── metadataresult.fxml ├── networkcreator.fxml ├── neuralinterface.fxml ├── singleimage.fxml └── traininginterface.fxml ├── icon ├── icon.png └── icon_high.png └── stylesheets └── main.css /.gitignore: -------------------------------------------------------------------------------- 1 | /nbproject/private/ 2 | /dist/ 3 | /build/ 4 | /output/ 5 | /tmp/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fake Image Detection Using Machine Learning 2 | 3 | The objective of this project is to identify fake images(Fake images are the images that are digitally altered images). The problem with existing fake image detection system is that they can be used detect only specific tampering methods like splicing, coloring etc. We approached the problem using machine learning and neural network to detect almost all kinds of tampering on images. 4 | 5 | Using latest image editing softwares, it is possible to make alterations on image which are too difficult for human eye to detect. Even with a complex neural network, it is not possible to determine whether an image is fake or not without identifying a common factor across almost all fake images. So, instead of giving direct raw pixels to the neural network, we gave error level analysed image. 6 | 7 | This project provides two level analysis for the image. At first level, it checks the image metadata. Image metadata is not that much reliable since it can be altered using simple programs. But most of the images we come across will have non-altered metadata which helps to identify the alterations. For example, if an image is edited with Adobe Photoshop, the metadata will contain even the version of the Adobe Photoshop used. 8 | 9 | In the second level, the image is converted into error level analysed format and will be resized to 100px x 100px image. Then these 10,000 pixels with RGB values (30,000 inputs) is given in to the input layer of Multilayer perceptron network. Output layer contain two neurons. One for fake image and one for real image. Depending upon the value of these neuron outputs along with metadata analyser output, we determine whether the image is fake or not and how much chance is there for the given image to be tampered. 10 | 11 | ### Feature Engineering 12 | 1. Dr. Neal Krawetz proposed a method called [Error Level Analysis(ELA)](http://www.hackerfactor.com/papers/bh-usa-07-krawetz-wp.pdf) that exploits the lossy compression of JPEG images. When an image is altered, the compression ratio of the specific portion changes with respect to other parts. A well trained neural network can detect the anomaly by and determine whether the image is fake or not. 13 | 2. The second parameter considered is metadata of the image. A parallel module is added to the program which checks the metadata to determine the signature of various image editing programs. Since it is costly to execute a neural network, the metadata inspection will considerably increase the performance by detecting tampering at an early stage. 14 | 15 | ### Neural network structure 16 | | Layer | Neurons | 17 | | ------------- | ------------- | 18 | | Input Layer | 30,000 | 19 | | Hidden Layer 1 | 5000 - Sigmoid | 20 | | Hidden Layer 2 | 1000 - Sigmoid | 21 | | Hidden Layer 3 | 100 - Sigmoid | 22 | | Output Layer | 2 | 23 | 24 | 25 | ### Watch on YouTube 26 | [![Watch a video](https://img.youtube.com/vi/MVIN9HrS8UY/0.jpg)](https://www.youtube.com/watch?v=MVIN9HrS8UY) 27 | 28 | ### Tools Used 29 | 30 | #### [Neuroph Studio](http://neuroph.sourceforge.net/) 31 | Neuroph studio is an open source Java neural network framework that helps to easily build and use neural networks. It also provides a direct interface for loading images 32 | #### [Metadata-extractor](https://github.com/drewnoakes/metadata-extractor) 33 | Metadata-extractor is an open source java library used to extract metadata from images. 34 | #### [JavaFX](http://docs.oracle.com/javase/8/javase-clienttechnologies.htm) 35 | JavaFX is used to implement modern user interface for the application. 36 | 37 | ### Flow Chart : Detection 38 | 39 | 40 | ### Flow Chart : Training 41 | 42 | 43 | ### Project Status 44 | - [x] Implement Metadata Procesing Module 45 | - [x] Design a User Interface 46 | - [x] Implement Image Feature Extractor 47 | - [x] Design Neural Network using Neuroph Studio 48 | - [x] Implement Neural Network interface with JavaFX 49 | - [x] Connect Neural Network 50 | - [x] Integrate Neural Network to Master 51 | - [x] Train Network 52 | - [x] Test Network 53 | - [x] Read feedback from user and learn instantly 54 | - [x] Add network training interface 55 | - [x] Add module to apply error level analysis on a set of images 56 | - [x] Improve look and feel 57 | - [x] Train with more data 58 | - [x] Add batch testing module 59 | - [x] Detach User Inteface from core 60 | - [x] Implement Command Line Interface 61 | - [ ] Reach success rate of 90% 62 | 63 | Journal link : https://www.academia.edu/37977449/Fake_Image_Detection_Using_Machine_Learning 64 | 65 | 66 | ### Screenshots 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /build.xml: -------------------------------------------------------------------------------- 1 | 2 | Builds, tests, and runs the project Fake Image Detection. 3 | 4 | 53 | 54 | -------------------------------------------------------------------------------- /lib/commons-io-2.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afsalashyana/FakeImageDetection/7466fa9f3b01a5e34987651a51aab9172a118bf6/lib/commons-io-2.5.jar -------------------------------------------------------------------------------- /lib/ij.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afsalashyana/FakeImageDetection/7466fa9f3b01a5e34987651a51aab9172a118bf6/lib/ij.jar -------------------------------------------------------------------------------- /lib/jfoenix.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afsalashyana/FakeImageDetection/7466fa9f3b01a5e34987651a51aab9172a118bf6/lib/jfoenix.jar -------------------------------------------------------------------------------- /lib/logback-classic-1.1.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afsalashyana/FakeImageDetection/7466fa9f3b01a5e34987651a51aab9172a118bf6/lib/logback-classic-1.1.7.jar -------------------------------------------------------------------------------- /lib/logback-core-1.1.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afsalashyana/FakeImageDetection/7466fa9f3b01a5e34987651a51aab9172a118bf6/lib/logback-core-1.1.7.jar -------------------------------------------------------------------------------- /lib/metadata-extractor-2.9.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afsalashyana/FakeImageDetection/7466fa9f3b01a5e34987651a51aab9172a118bf6/lib/metadata-extractor-2.9.1.jar -------------------------------------------------------------------------------- /lib/neuroph-core-2.92.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afsalashyana/FakeImageDetection/7466fa9f3b01a5e34987651a51aab9172a118bf6/lib/neuroph-core-2.92.jar -------------------------------------------------------------------------------- /lib/neuroph-imgrec-2.92.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afsalashyana/FakeImageDetection/7466fa9f3b01a5e34987651a51aab9172a118bf6/lib/neuroph-imgrec-2.92.jar -------------------------------------------------------------------------------- /lib/slf4j-api-1.7.21.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afsalashyana/FakeImageDetection/7466fa9f3b01a5e34987651a51aab9172a118bf6/lib/slf4j-api-1.7.21.jar -------------------------------------------------------------------------------- /lib/xmpcore-5.1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afsalashyana/FakeImageDetection/7466fa9f3b01a5e34987651a51aab9172a118bf6/lib/xmpcore-5.1.2.jar -------------------------------------------------------------------------------- /manifest.mf: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | X-COMMENT: Main-Class will be added automatically by build 3 | 4 | -------------------------------------------------------------------------------- /nbproject/UPDATED.TXT: -------------------------------------------------------------------------------- 1 | ================================================= 2 | Project Fake Image Detection build script updated 3 | ================================================= 4 | 5 | Project build script file jfx-impl.xml in nbproject sub-directory has not been recognized 6 | as compliant with this version of NetBeans JavaFX support module. To ensure correct 7 | and complete functionality within this NetBeans installation the script file has been 8 | backed up to jfx-impl_backup_6.xml and then updated to the currently supported state. 9 | 10 | FX Project build script auto-update may be triggered on project open either after 11 | NetBeans installation update or by manual changes in jfx-impl.xml. Please note that 12 | changing jfx-impl.xml manually is not recommended. Any build customization code should 13 | be placed only in build.xml in project root directory. 14 | 15 | Remark: The auto-update mechanism can be disabled by setting property 16 | javafx.disable.autoupdate=true 17 | Automatic opening of this notification when project files are updated can be disabled by setting property 18 | javafx.disable.autoupdate.notification=true 19 | (in build.properties, private.properties or project.properties). 20 | 21 | Remark: Files nbproject/jfx-impl_backup*.xml and this file nbproject/UPDATED.TXT 22 | are not used when building the project and can be freely deleted. 23 | 24 | -------------------------------------------------------------------------------- /nbproject/configs/Run_as_WebStart.properties: -------------------------------------------------------------------------------- 1 | # Do not modify this property in this configuration. It can be re-generated. 2 | $label=Run as WebStart 3 | -------------------------------------------------------------------------------- /nbproject/configs/Run_in_Browser.properties: -------------------------------------------------------------------------------- 1 | # Do not modify this property in this configuration. It can be re-generated. 2 | $label=Run in Browser 3 | -------------------------------------------------------------------------------- /nbproject/genfiles.properties: -------------------------------------------------------------------------------- 1 | build.xml.data.CRC32=6f51bc78 2 | build.xml.script.CRC32=91121d0f 3 | build.xml.stylesheet.CRC32=8064a381@1.79.1.48 4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. 5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. 6 | nbproject/build-impl.xml.data.CRC32=6f51bc78 7 | nbproject/build-impl.xml.script.CRC32=0feb16f7 8 | nbproject/build-impl.xml.stylesheet.CRC32=05530350@1.79.1.48 9 | -------------------------------------------------------------------------------- /nbproject/project.properties: -------------------------------------------------------------------------------- 1 | annotation.processing.enabled=true 2 | annotation.processing.enabled.in.editor=false 3 | annotation.processing.processors.list= 4 | annotation.processing.run.all.processors=true 5 | annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output 6 | application.title=Fake Image Detection 7 | application.vendor=afsal 8 | build.classes.dir=${build.dir}/classes 9 | build.classes.excludes=**/*.java,**/*.form 10 | # This directory is removed when the project is cleaned: 11 | build.dir=build 12 | build.generated.dir=${build.dir}/generated 13 | build.generated.sources.dir=${build.dir}/generated-sources 14 | # Only compile against the classpath explicitly listed here: 15 | build.sysclasspath=ignore 16 | build.test.classes.dir=${build.dir}/test/classes 17 | build.test.results.dir=${build.dir}/test/results 18 | compile.on.save=true 19 | compile.on.save.unsupported.javafx=true 20 | # Uncomment to specify the preferred debugger connection transport: 21 | #debug.transport=dt_socket 22 | debug.classpath=\ 23 | ${run.classpath} 24 | debug.test.classpath=\ 25 | ${run.test.classpath} 26 | # This directory is removed when the project is cleaned: 27 | dist.dir=dist 28 | dist.jar=${dist.dir}/Fake Image Detection.jar 29 | dist.javadoc.dir=${dist.dir}/javadoc 30 | endorsed.classpath= 31 | excludes= 32 | file.reference.commons-io-2.5.jar=lib/commons-io-2.5.jar 33 | file.reference.ij.jar=lib/ij.jar 34 | file.reference.jfoenix.jar=lib/jfoenix.jar 35 | file.reference.logback-classic-1.1.7.jar=lib/logback-classic-1.1.7.jar 36 | file.reference.logback-core-1.1.7.jar=lib/logback-core-1.1.7.jar 37 | file.reference.metadata-extractor-2.9.1.jar=lib/metadata-extractor-2.9.1.jar 38 | file.reference.neuroph-core-2.92.jar=lib/neuroph-core-2.92.jar 39 | file.reference.neuroph-imgrec-2.92.jar=lib/neuroph-imgrec-2.92.jar 40 | file.reference.slf4j-api-1.7.21.jar=lib/slf4j-api-1.7.21.jar 41 | file.reference.xmpcore-5.1.2.jar=lib/xmpcore-5.1.2.jar 42 | includes=** 43 | # Non-JavaFX jar file creation is deactivated in JavaFX 2.0+ projects 44 | jar.archive.disabled=true 45 | jar.compress=false 46 | javac.classpath=\ 47 | ${javafx.classpath.extension}:\ 48 | ${file.reference.jfoenix.jar}:\ 49 | ${file.reference.metadata-extractor-2.9.1.jar}:\ 50 | ${file.reference.xmpcore-5.1.2.jar}:\ 51 | ${file.reference.ij.jar}:\ 52 | ${file.reference.neuroph-core-2.92.jar}:\ 53 | ${file.reference.neuroph-imgrec-2.92.jar}:\ 54 | ${file.reference.slf4j-api-1.7.21.jar}:\ 55 | ${file.reference.logback-classic-1.1.7.jar}:\ 56 | ${file.reference.logback-core-1.1.7.jar}:\ 57 | ${file.reference.commons-io-2.5.jar} 58 | # Space-separated list of extra javac options 59 | javac.compilerargs= 60 | javac.deprecation=false 61 | javac.external.vm=false 62 | javac.processorpath=\ 63 | ${javac.classpath} 64 | javac.source=1.8 65 | javac.target=1.8 66 | javac.test.classpath=\ 67 | ${javac.classpath}:\ 68 | ${build.classes.dir} 69 | javac.test.processorpath=\ 70 | ${javac.test.classpath} 71 | javadoc.additionalparam= 72 | javadoc.author=false 73 | javadoc.encoding=${source.encoding} 74 | javadoc.noindex=false 75 | javadoc.nonavbar=false 76 | javadoc.notree=false 77 | javadoc.private=false 78 | javadoc.splitindex=true 79 | javadoc.use=true 80 | javadoc.version=false 81 | javadoc.windowtitle= 82 | javafx.application.implementation.version=1.0 83 | javafx.binarycss=false 84 | javafx.classpath.extension=\ 85 | ${java.home}/lib/javaws.jar:\ 86 | ${java.home}/lib/deploy.jar:\ 87 | ${java.home}/lib/plugin.jar 88 | javafx.deploy.adddesktopshortcut=false 89 | javafx.deploy.addstartmenushortcut=false 90 | javafx.deploy.allowoffline=true 91 | # If true, application update mode is set to 'background', if false, update mode is set to 'eager' 92 | javafx.deploy.backgroundupdate=false 93 | javafx.deploy.disable.proxy=false 94 | javafx.deploy.embedJNLP=true 95 | javafx.deploy.includeDT=true 96 | javafx.deploy.installpermanently=false 97 | javafx.deploy.permissionselevated=false 98 | # Set true to prevent creation of temporary copy of deployment artifacts before each run (disables concurrent runs) 99 | javafx.disable.concurrent.runs=false 100 | # Set true to enable multiple concurrent runs of the same WebStart or Run-in-Browser project 101 | javafx.enable.concurrent.external.runs=false 102 | # This is a JavaFX project 103 | javafx.enabled=true 104 | javafx.fallback.class=com.javafx.main.NoJavaFXFallback 105 | # Main class for JavaFX 106 | javafx.main.class=com.gc.fakeimagedetection.ui.Main 107 | javafx.preloader.class= 108 | # This project does not use Preloader 109 | javafx.preloader.enabled=false 110 | javafx.preloader.jar.filename= 111 | javafx.preloader.jar.path= 112 | javafx.preloader.project.path= 113 | javafx.preloader.type=none 114 | # Set true for GlassFish only. Rebases manifest classpaths of JARs in lib dir. Not usable with signed JARs. 115 | javafx.rebase.libs=false 116 | javafx.run.height=600 117 | javafx.run.width=800 118 | javafx.signing.blob=false 119 | javafx.signing.enabled=false 120 | javafx.signing.type=notsigned 121 | # Pre-JavaFX 2.0 WebStart is deactivated in JavaFX 2.0+ projects 122 | jnlp.enabled=false 123 | # Main class for Java launcher 124 | main.class=com.javafx.main.Main 125 | # For improved security specify narrower Codebase manifest attribute to prevent RIAs from being repurposed 126 | manifest.custom.codebase=* 127 | # Specify Permissions manifest attribute to override default (choices: sandbox, all-permissions) 128 | manifest.custom.permissions= 129 | manifest.file=manifest.mf 130 | meta.inf.dir=${src.dir}/META-INF 131 | mkdist.disabled=false 132 | native.bundling.enabled=false 133 | platform.active=default_platform 134 | run.classpath=\ 135 | ${dist.jar}:\ 136 | ${javac.classpath}:\ 137 | ${build.classes.dir} 138 | run.jvmargs=-Xmx64m -Xmx6096m 139 | run.test.classpath=\ 140 | ${javac.test.classpath}:\ 141 | ${build.test.classes.dir} 142 | source.encoding=UTF-8 143 | src.dir=src 144 | test.src.dir=test 145 | -------------------------------------------------------------------------------- /nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.java.j2seproject 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Fake Image Detection 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /nnet/CNN2.nnet: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afsalashyana/FakeImageDetection/7466fa9f3b01a5e34987651a51aab9172a118bf6/nnet/CNN2.nnet -------------------------------------------------------------------------------- /nnet/CNN_V1.0.nnet: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afsalashyana/FakeImageDetection/7466fa9f3b01a5e34987651a51aab9172a118bf6/nnet/CNN_V1.0.nnet -------------------------------------------------------------------------------- /nnet/CNN_V2.0.nnet: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afsalashyana/FakeImageDetection/7466fa9f3b01a5e34987651a51aab9172a118bf6/nnet/CNN_V2.0.nnet -------------------------------------------------------------------------------- /nnet/CNN_V3.0.nnet: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afsalashyana/FakeImageDetection/7466fa9f3b01a5e34987651a51aab9172a118bf6/nnet/CNN_V3.0.nnet -------------------------------------------------------------------------------- /nnet/MLPV2.0.nnet: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afsalashyana/FakeImageDetection/7466fa9f3b01a5e34987651a51aab9172a118bf6/nnet/MLPV2.0.nnet -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/core/FIDNetworkAnalyser.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.core; 2 | 3 | import com.gc.fakeimagedetection.core.errorlevelanalysis.FIDErrorLevelAnalysis; 4 | import com.gc.fakeimagedetection.core.listener.ErrorLevelAnalysisListener; 5 | import java.awt.Dimension; 6 | import java.awt.image.BufferedImage; 7 | import java.io.FileInputStream; 8 | import java.io.FileNotFoundException; 9 | import java.util.HashMap; 10 | import org.neuroph.core.NeuralNetwork; 11 | import org.neuroph.imgrec.ImageRecognitionPlugin; 12 | 13 | public class FIDNetworkAnalyser implements ErrorLevelAnalysisListener { 14 | 15 | private NeuralNetwork nnet; 16 | 17 | public FIDNetworkAnalyser(String nSourceFile) throws FileNotFoundException { 18 | nnet = NeuralNetwork.load(new FileInputStream(nSourceFile)); // load trained neural network saved with Neuroph Studio 19 | } 20 | 21 | public static void main(String[] args) throws FileNotFoundException { 22 | if (args == null || args.length < 5) { 23 | System.err.println("Usage : "); 24 | } 25 | String neuralSource = args[0]; 26 | String imageLoc = args[1]; 27 | String quality = args[2]; 28 | String sWidth = args[3]; 29 | String sHeight = args[4]; 30 | 31 | new FIDNetworkAnalyser(neuralSource) 32 | .run(imageLoc, Integer.parseInt(quality), 33 | new Dimension(Integer.parseInt(sWidth), Integer.parseInt(sHeight))); 34 | 35 | } 36 | 37 | private void run(String imageLocation, int quality, Dimension dim) { 38 | FIDErrorLevelAnalysis elaAnalyzer = new FIDErrorLevelAnalysis(imageLocation, quality, dim, this); 39 | elaAnalyzer.start(); 40 | } 41 | 42 | public void processOnNeuralNetwork(BufferedImage elaImage) { 43 | ImageRecognitionPlugin imageRecognition = (ImageRecognitionPlugin) nnet.getPlugin(ImageRecognitionPlugin.class); // get the image recognition plugin from neural network 44 | HashMap output = imageRecognition.recognizeImage(elaImage); 45 | if (output == null) { 46 | System.err.println("Image Recognition Failed"); 47 | } 48 | System.out.println(output.toString()); 49 | } 50 | 51 | @Override 52 | public void elaCompleted(BufferedImage image) { 53 | if(image==null) 54 | return; 55 | processOnNeuralNetwork(image); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/core/FIDNetworkTrainer.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.core; 2 | 3 | import com.gc.fakeimagedetection.core.listener.BatchImageTrainingListener; 4 | import com.gc.fakeimagedetection.core.trainer.BatchImageTrainer; 5 | import java.awt.Dimension; 6 | import java.io.File; 7 | import java.util.ArrayList; 8 | import java.util.Arrays; 9 | 10 | public class FIDNetworkTrainer implements BatchImageTrainingListener { 11 | 12 | private final float MERROR = 0.01f; 13 | private final float LEARNING_RATE = 0.1f; 14 | private final float MOMENTUM = 0.7f; 15 | 16 | public static void main(String[] args) { 17 | if (args == null || args.length < 5) { 18 | System.err.println("usage : "); 19 | return; 20 | } 21 | 22 | String sourceDir = args[0]; 23 | String neuralDir = args[1]; 24 | String sWidth = args[2]; 25 | String sHeight = args[3]; 26 | String imageLabelString = args[4]; 27 | 28 | new FIDNetworkTrainer().run(sourceDir, neuralDir, sWidth, sHeight, imageLabelString); 29 | } 30 | 31 | @Override 32 | public void batchImageTrainingCompleted() { 33 | System.out.println("Training Completed"); 34 | } 35 | 36 | @Override 37 | public void batchImageTrainingUpdate(int iteration, Double error) { 38 | System.out.println("Iteration " + iteration + "\t Error = " + error); 39 | } 40 | 41 | private void run(String sourceDir, String neuralDir, String sWidth, String sHeight, String imageLabelString) { 42 | ArrayList labels = new ArrayList<>(); 43 | labels.addAll(Arrays.asList(imageLabelString.split(","))); 44 | BatchImageTrainer neuralTrainer 45 | = new BatchImageTrainer(new File(sourceDir), new File(neuralDir), 46 | new Dimension(Integer.parseInt(sWidth), Integer.parseInt(sHeight)), labels, this); 47 | neuralTrainer.setMaxError(MERROR); 48 | neuralTrainer.setMomentum(MOMENTUM); 49 | neuralTrainer.setLearningRate(LEARNING_RATE); 50 | neuralTrainer.start(); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/core/FIDPreprocessor.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.core; 2 | 3 | import com.gc.fakeimagedetection.core.errorlevelanalysis.ImageStandardizer; 4 | import java.awt.Dimension; 5 | import java.io.File; 6 | 7 | public class FIDPreprocessor { 8 | 9 | public static void main(String[] args) { 10 | if (args == null || args.length < 5) { 11 | System.err.println("Usage : "); 12 | return; 13 | } 14 | String srcDir = args[0]; 15 | String destDir = args[1]; 16 | String sWidth = args[2]; 17 | String sHeight = args[3]; 18 | String outLabel = args[4]; 19 | 20 | ImageStandardizer preprocessor 21 | = new ImageStandardizer(new File(srcDir), new File(destDir), 22 | new Dimension(Integer.parseInt(sWidth), Integer.parseInt(sHeight)), outLabel); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/core/constants/ConstantObjects.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.core.constants; 2 | 3 | public class ConstantObjects { 4 | 5 | public static String[] supportedExtensions 6 | = {"JPG", "jpg", "JPEG", "PNG", "png", "TIFF", "TIF", "tif"}; 7 | public static String neuralNetworkPath = "nnet/MLPV2.0.nnet"; 8 | public static Boolean shouldPropogateResult = true; 9 | public static float fakeness = -1; 10 | public static float realness = -1; 11 | } 12 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/core/errorlevelanalysis/ErrorLevelAnalyzer.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.core.errorlevelanalysis; 2 | 3 | import com.gc.fakeimagedetection.core.listener.ErrorLevelAnalysisUpdateListener; 4 | import com.gc.fakeimagedetection.ui.alert.Calert; 5 | import com.gc.fakeimagedetection.core.multithread.NotifyingThread; 6 | import ij.ImagePlus; 7 | import ij.io.FileSaver; 8 | import static ij.io.FileSaver.setJpegQuality; 9 | import ij.plugin.ContrastEnhancer; 10 | import ij.plugin.ImageCalculator; 11 | import ij.process.ImageProcessor; 12 | import java.awt.Dimension; 13 | import java.awt.Image; 14 | import java.awt.Rectangle; 15 | import java.io.File; 16 | import java.io.IOException; 17 | import java.text.DecimalFormat; 18 | import java.util.ArrayList; 19 | import javafx.scene.control.Alert; 20 | import javax.imageio.ImageIO; 21 | 22 | public class ErrorLevelAnalyzer extends NotifyingThread { 23 | 24 | String fileLocation; 25 | String destination = "output/processed"; 26 | int quality = 95; 27 | Boolean runningStatus = false; 28 | Dimension sampledDimension; 29 | String outLabel; 30 | ArrayList supportedExtensions; 31 | ErrorLevelAnalysisUpdateListener listener; 32 | int baseCount = 1; 33 | 34 | public ErrorLevelAnalyzer(String fileLocation, String destination, int quality) { 35 | this.fileLocation = fileLocation; 36 | this.destination = destination + "/"; 37 | this.quality = quality; 38 | } 39 | 40 | public void setListener(ErrorLevelAnalysisUpdateListener listener) { 41 | this.listener = listener; 42 | } 43 | 44 | public ErrorLevelAnalyzer(String dirLoc, String destination, int quality, ArrayList supportedExtensions, Dimension dimension, String outLabel) { 45 | this.fileLocation = dirLoc; 46 | this.quality = quality; 47 | this.sampledDimension = dimension; 48 | this.supportedExtensions = supportedExtensions; 49 | this.destination = destination + "/"; 50 | this.outLabel = outLabel; 51 | } 52 | 53 | public void setSampledDimension(Dimension sampledDimension) { 54 | this.sampledDimension = sampledDimension; 55 | } 56 | 57 | public Dimension getSampledDimension() { 58 | return sampledDimension; 59 | } 60 | 61 | @Override 62 | public void doRun() { 63 | try { 64 | System.out.println("Changing Images to size " + sampledDimension); 65 | 66 | File[] availableFiles = new File(fileLocation).listFiles(); 67 | float totalSize = availableFiles.length; 68 | float processedSize = 0; 69 | checkForImageConflict(); 70 | 71 | for (File file : availableFiles) { 72 | String ext = file.getName().split("[.]")[1]; 73 | if (!supportedExtensions.contains(ext)) { 74 | System.out.println("Dropping " + file.getName() + " due to unsupported extension --" + file.getName().split("[.]")[1]); 75 | continue; 76 | } 77 | runningStatus = true; 78 | Image img; 79 | try { 80 | img = ImageIO.read(file); 81 | } catch (IOException ex) { 82 | System.err.println("Null Image"); 83 | return; 84 | } 85 | ImagePlus orig = new ImagePlus("Source Image", img); 86 | if (orig.getWidth() < sampledDimension.getWidth() || orig.getHeight() < sampledDimension.getHeight()) { 87 | System.err.println("Too Small to process"); 88 | continue; 89 | } 90 | 91 | String basePath = "output/"; 92 | String origPath = basePath + "original.jpg"; 93 | String resavedPath = basePath + "resaved.jpg"; 94 | String elaPath = basePath + "ELA.png"; 95 | 96 | FileSaver fs = new FileSaver(orig); 97 | setJpegQuality(100); 98 | fs.saveAsJpeg(origPath); 99 | 100 | setJpegQuality(quality); 101 | fs.saveAsJpeg(resavedPath); 102 | ImagePlus resaved = new ImagePlus(resavedPath); 103 | 104 | ImageCalculator calc = new ImageCalculator(); 105 | ImagePlus diff; 106 | try { 107 | diff = calc.run("create difference", orig, resaved); 108 | } catch (Exception e) { 109 | Calert.showAlert("Error Occured", e.getMessage(), Alert.AlertType.ERROR); 110 | continue; 111 | } 112 | diff.setTitle("ELA @ " + quality + "%"); 113 | 114 | ContrastEnhancer c = new ContrastEnhancer(); 115 | c.stretchHistogram(diff, 0.05); 116 | 117 | ImageProcessor ip = diff.getProcessor(); 118 | ImageProcessor imp; 119 | if (ip.getWidth() > ip.getHeight()) { 120 | Rectangle rec = new Rectangle(0, 0, ip.getHeight(), ip.getHeight()); 121 | ip.setRoi(rec); 122 | imp = ip.crop(); 123 | } else { 124 | Rectangle rec = new Rectangle(0, 0, ip.getWidth(), ip.getWidth()); 125 | ip.setRoi(rec); 126 | imp = ip.crop(); 127 | } 128 | imp = imp.resize((int) sampledDimension.getWidth(), (int) sampledDimension.getHeight()); 129 | FileSaver resultSaver = new FileSaver(new ImagePlus("Result", imp.getBufferedImage())); 130 | 131 | DecimalFormat format = new DecimalFormat("#"); 132 | String savePath = destination + outLabel + format.format(baseCount + processedSize) + ".png"; 133 | resultSaver.saveAsPng(savePath); 134 | 135 | runningStatus = false; 136 | 137 | float percentage = processedSize / totalSize; 138 | 139 | String status = "Processing " + file.getName() + " " + format.format(processedSize) + " / " + format.format(totalSize); 140 | listener.iterationCompleted(status, percentage); 141 | processedSize++; 142 | 143 | } 144 | } catch (Exception e) { 145 | System.err.println("Error Occured at Ela_processor :" + e.getMessage()); 146 | } 147 | } 148 | 149 | private void checkForImageConflict() { 150 | baseCount = 1; 151 | while (true) { 152 | String savePath = destination + outLabel + (baseCount + 1) + ".png"; 153 | if (new File(savePath).exists()) { 154 | baseCount++; 155 | } else { 156 | break; 157 | } 158 | } 159 | System.out.println("There are " + (baseCount - 1) + " images already. Starting from " + baseCount); 160 | } 161 | 162 | } 163 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/core/errorlevelanalysis/FIDErrorLevelAnalysis.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.core.errorlevelanalysis; 2 | 3 | import com.gc.fakeimagedetection.core.listener.ErrorLevelAnalysisListener; 4 | import com.gc.fakeimagedetection.core.multithread.NotifyingThread; 5 | import com.gc.fakeimagedetection.ui.alert.Calert; 6 | import ij.ImagePlus; 7 | import ij.io.FileSaver; 8 | import static ij.io.FileSaver.setJpegQuality; 9 | import ij.plugin.ContrastEnhancer; 10 | import ij.plugin.ImageCalculator; 11 | import ij.process.ImageProcessor; 12 | import java.awt.Dimension; 13 | import java.awt.Image; 14 | import java.awt.Rectangle; 15 | import java.io.File; 16 | import java.io.IOException; 17 | import javafx.application.Platform; 18 | import javafx.scene.control.Alert; 19 | import javax.imageio.ImageIO; 20 | 21 | public class FIDErrorLevelAnalysis extends NotifyingThread { 22 | 23 | String fileLocation; 24 | int quality = 95; 25 | Boolean runningStatus = false; 26 | Dimension sampledDimension; 27 | ErrorLevelAnalysisListener listener; 28 | 29 | public FIDErrorLevelAnalysis(String fileLocation, 30 | int quality, Dimension sampledDimension, ErrorLevelAnalysisListener listener) { 31 | this.fileLocation = fileLocation; 32 | this.quality = quality; 33 | this.sampledDimension = sampledDimension; 34 | this.listener = listener; 35 | } 36 | 37 | @Override 38 | public void doRun() { 39 | try { 40 | Image img; 41 | try { 42 | System.out.println("Loading Image :" + fileLocation); 43 | img = ImageIO.read(new File(fileLocation)); 44 | } catch (IOException ex) { 45 | System.err.println("Null Image"); 46 | return; 47 | } 48 | System.out.println("Dimension is set to " + sampledDimension); 49 | ImagePlus orig = new ImagePlus("Source Image", img); 50 | 51 | String basePath = "tmp/"; 52 | File file = new File(basePath); 53 | if (!file.exists()) { 54 | file.mkdir(); 55 | } 56 | String origPath = basePath + "-original.jpg"; 57 | String resavedPath = basePath + "-resaved.jpg"; 58 | String elaPath = basePath + "-ELA.png"; 59 | 60 | FileSaver fs = new FileSaver(orig); 61 | setJpegQuality(100); 62 | fs.saveAsJpeg(origPath); 63 | 64 | setJpegQuality(quality); 65 | fs.saveAsJpeg(resavedPath); 66 | ImagePlus resaved = new ImagePlus(resavedPath); 67 | 68 | ImageCalculator calc = new ImageCalculator(); 69 | ImagePlus diff = calc.run("create difference", orig, resaved); 70 | diff.setTitle("ELA @ " + quality + "%"); 71 | 72 | ContrastEnhancer c = new ContrastEnhancer(); 73 | c.stretchHistogram(diff, 0.05); 74 | ImageProcessor ip = diff.getProcessor(); 75 | 76 | ImageProcessor imp; 77 | if (ip.getWidth() > ip.getHeight()) { 78 | Rectangle rec = new Rectangle(0, 0, ip.getHeight(), ip.getHeight()); 79 | ip.setRoi(rec); 80 | imp = ip.crop(); 81 | } else { 82 | Rectangle rec = new Rectangle(0, 0, ip.getWidth(), ip.getWidth()); 83 | ip.setRoi(rec); 84 | imp = ip.crop(); 85 | } 86 | 87 | imp = imp.resize((int) sampledDimension.getWidth(), (int) sampledDimension.getHeight()); 88 | listener.elaCompleted(imp.getBufferedImage()); 89 | } catch (Exception e) { 90 | //JavaFX UI thread is different from current Thread 91 | System.err.println(e.toString()); 92 | Platform.runLater(new Runnable() { 93 | @Override 94 | public void run() { 95 | Calert.showAlert("Fatal Error Occured", "Neural Network Error", Alert.AlertType.ERROR); 96 | } 97 | }); 98 | listener.elaCompleted(null); 99 | } 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/core/errorlevelanalysis/ImageStandardizer.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.core.errorlevelanalysis; 2 | 3 | import com.gc.fakeimagedetection.core.listener.ErrorLevelAnalysisUpdateListener; 4 | import com.gc.fakeimagedetection.core.constants.ConstantObjects; 5 | import com.gc.fakeimagedetection.core.listener.ThreadCompleteListener; 6 | import java.awt.Dimension; 7 | import java.io.File; 8 | import java.util.ArrayList; 9 | import java.util.Arrays; 10 | 11 | public final class ImageStandardizer implements ThreadCompleteListener { 12 | 13 | File sourceDir = null; 14 | File destDir = null; 15 | Dimension resolution = null; 16 | File[] availableFiles = null; 17 | ArrayList supportedExtensions; 18 | ErrorLevelAnalysisUpdateListener listener; 19 | String outputLabel; 20 | 21 | public ImageStandardizer(File sourceDirectory, File destinationDirectory, Dimension finalResolution, String outLabel) { 22 | System.out.println("Starting new Image Standardizer"); 23 | sourceDir = sourceDirectory; 24 | resolution = finalResolution; 25 | destDir = destinationDirectory; 26 | outputLabel = outLabel; 27 | } 28 | 29 | public void run() { 30 | init(); 31 | loadDirectory(sourceDir.getAbsolutePath()); 32 | processImages(outputLabel); 33 | 34 | } 35 | 36 | public void setListener(ErrorLevelAnalysisUpdateListener listener) { 37 | this.listener = listener; 38 | } 39 | 40 | void init() { 41 | supportedExtensions = new ArrayList<>(Arrays.asList(ConstantObjects.supportedExtensions)); 42 | } 43 | 44 | void processImages(String outLabel) { 45 | System.out.println("Calling Processor with dimension " + resolution); 46 | ErrorLevelAnalyzer imageProcessor 47 | = new ErrorLevelAnalyzer(sourceDir.getAbsolutePath(), destDir.getAbsolutePath(), 95, supportedExtensions, resolution, outLabel); 48 | imageProcessor.setListener(listener); 49 | imageProcessor.addListener(this); 50 | imageProcessor.start(); 51 | } 52 | 53 | public void loadDirectory(String path) { 54 | System.out.println("Loading directory...."); 55 | sourceDir = new File(path); 56 | if (!sourceDir.exists() || sourceDir.isFile()) { 57 | System.out.println("Not a valid directory"); 58 | return; 59 | } 60 | availableFiles = sourceDir.listFiles(); 61 | if (availableFiles == null) { 62 | return; 63 | } 64 | System.out.println("Total " + availableFiles.length + " files are available"); 65 | } 66 | 67 | @Override 68 | public void notifyOfThreadComplete(Thread thread) { 69 | System.out.println("Image Processing Completed"); 70 | System.exit(0); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/core/listener/BatchImageTestingListener.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.core.listener; 2 | 3 | public interface BatchImageTestingListener { 4 | 5 | public void testingComplete(String result); 6 | } 7 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/core/listener/BatchImageTrainingListener.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.core.listener; 2 | 3 | public interface BatchImageTrainingListener { 4 | 5 | public void batchImageTrainingCompleted(); 6 | 7 | public void batchImageTrainingUpdate(int iteration, Double error); 8 | } 9 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/core/listener/ErrorLevelAnalysisListener.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.core.listener; 2 | 3 | import java.awt.image.BufferedImage; 4 | 5 | public interface ErrorLevelAnalysisListener { 6 | 7 | public void elaCompleted(BufferedImage image); 8 | } 9 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/core/listener/ErrorLevelAnalysisUpdateListener.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.core.listener; 2 | 3 | public interface ErrorLevelAnalysisUpdateListener { 4 | 5 | public void iterationCompleted(String file, Float percentage); 6 | } 7 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/core/listener/NeuralNetworkCreationCompleteListener.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.core.listener; 2 | 3 | public interface NeuralNetworkCreationCompleteListener { 4 | 5 | public void networkCreationComplete(Boolean flag); 6 | } 7 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/core/listener/NeuralnetProcessorListener.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.core.listener; 2 | 3 | import java.util.HashMap; 4 | 5 | public interface NeuralnetProcessorListener { 6 | 7 | public void neuralnetProcessCompleted(HashMap result); 8 | } 9 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/core/listener/ThreadCompleteListener.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.core.listener; 2 | 3 | public interface ThreadCompleteListener { 4 | 5 | void notifyOfThreadComplete(final Thread thread); 6 | } 7 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/core/metadata/MetadataProcessor.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.core.metadata; 2 | 3 | import com.drew.imaging.ImageMetadataReader; 4 | import com.drew.metadata.Directory; 5 | import com.drew.metadata.Metadata; 6 | import com.drew.metadata.Tag; 7 | import java.io.File; 8 | import java.util.logging.Level; 9 | import java.util.logging.Logger; 10 | 11 | public class MetadataProcessor { 12 | 13 | File imageFile; 14 | public static String extracted_data = ""; 15 | Metadata data = null; 16 | 17 | public MetadataProcessor(File imageFile) { 18 | this.imageFile = imageFile; 19 | try { 20 | data = ImageMetadataReader.readMetadata(imageFile); 21 | } catch (Exception ex) { 22 | Logger.getLogger(MetadataProcessor.class.getName()).log(Level.SEVERE, null, ex); 23 | } 24 | 25 | for (Directory directory : data.getDirectories()) { 26 | extracted_data += String.format("----------------------------------------------%15s---------------------------------\n", directory.getName()); 27 | for (Tag tag : directory.getTags()) { 28 | extracted_data += tag + "\n"; 29 | } 30 | if (directory.hasErrors()) { 31 | for (String error : directory.getErrors()) { 32 | System.err.println("ERROR: " + error); 33 | } 34 | } 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/core/multithread/NotifyingThread.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.core.multithread; 2 | 3 | import com.gc.fakeimagedetection.core.listener.ThreadCompleteListener; 4 | import java.util.Set; 5 | import java.util.concurrent.CopyOnWriteArraySet; 6 | 7 | public abstract class NotifyingThread extends Thread { 8 | 9 | private final Set listeners 10 | = new CopyOnWriteArraySet<>(); 11 | 12 | public final void addListener(final ThreadCompleteListener listener) { 13 | listeners.add(listener); 14 | } 15 | 16 | public final void removeListener(final ThreadCompleteListener listener) { 17 | listeners.remove(listener); 18 | } 19 | 20 | private void notifyListeners() { 21 | listeners.stream().forEach((listener) -> { 22 | listener.notifyOfThreadComplete(this); 23 | }); 24 | } 25 | 26 | @Override 27 | public final void run() { 28 | try { 29 | doRun(); 30 | } finally { 31 | notifyListeners(); 32 | } 33 | } 34 | 35 | public abstract void doRun(); 36 | } 37 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/core/neuralnet/MLPNetworkMaker.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.core.neuralnet; 2 | 3 | import com.gc.fakeimagedetection.core.listener.NeuralNetworkCreationCompleteListener; 4 | import java.util.List; 5 | import org.neuroph.core.NeuralNetwork; 6 | import org.neuroph.imgrec.ColorMode; 7 | import org.neuroph.imgrec.ImageRecognitionHelper; 8 | import org.neuroph.imgrec.image.Dimension; 9 | import org.neuroph.util.TransferFunctionType; 10 | 11 | public class MLPNetworkMaker implements Runnable { 12 | 13 | String networkLabel; 14 | Dimension samplingDimension; 15 | ColorMode mode; 16 | List outputNeuronLabels; 17 | List neuronCounts; 18 | TransferFunctionType type; 19 | NeuralNetwork nnet; 20 | String saveLocation; 21 | NeuralNetworkCreationCompleteListener listener; 22 | 23 | public void setListener(NeuralNetworkCreationCompleteListener listener) { 24 | this.listener = listener; 25 | } 26 | 27 | public MLPNetworkMaker(String networkLabel, Dimension samplingDimension, ColorMode mode, List outputNeuronLabels, List neuronCounts, TransferFunctionType type, String saveLocation) { 28 | this.networkLabel = networkLabel; 29 | this.samplingDimension = samplingDimension; 30 | this.mode = mode; 31 | this.outputNeuronLabels = outputNeuronLabels; 32 | this.neuronCounts = neuronCounts; 33 | this.type = type; 34 | this.saveLocation = saveLocation; 35 | } 36 | 37 | @Override 38 | public void run() { 39 | Boolean flag = true; 40 | try { 41 | nnet = ImageRecognitionHelper.createNewNeuralNetwork(networkLabel, samplingDimension, mode, outputNeuronLabels, neuronCounts, type); 42 | if (nnet == null) { 43 | throw new Exception("Network Creation Failed"); 44 | } 45 | nnet.save(saveLocation); 46 | } catch (Exception e) { 47 | flag = false; 48 | } 49 | listener.networkCreationComplete(flag); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/core/processor/NeuralNetProcessor.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.core.processor; 2 | 3 | import com.gc.fakeimagedetection.core.constants.ConstantObjects; 4 | import com.gc.fakeimagedetection.core.listener.NeuralnetProcessorListener; 5 | import com.gc.fakeimagedetection.core.multithread.NotifyingThread; 6 | import java.awt.image.BufferedImage; 7 | import java.io.File; 8 | import java.io.FileInputStream; 9 | import java.io.FileNotFoundException; 10 | import java.io.IOException; 11 | import java.util.HashMap; 12 | import java.util.logging.Level; 13 | import java.util.logging.Logger; 14 | import javafx.application.Platform; 15 | import javafx.scene.control.Alert; 16 | import javafx.scene.control.Alert.AlertType; 17 | import javax.imageio.ImageIO; 18 | import org.neuroph.core.NeuralNetwork; 19 | import org.neuroph.imgrec.ImageRecognitionPlugin; 20 | 21 | public class NeuralNetProcessor extends NotifyingThread { 22 | 23 | static BufferedImage image; 24 | public static NeuralNetwork nnet; 25 | static ImageRecognitionPlugin imageRecognition; 26 | NeuralnetProcessorListener listener; 27 | 28 | public void setListener(NeuralnetProcessorListener listener) { 29 | this.listener = listener; 30 | } 31 | 32 | public static void main(String[] args) { 33 | try { 34 | System.out.println("usage java -jar nn.jar image_to_be_processed file_of_neural_network"); 35 | System.out.println("Loading Image...."); 36 | image = ImageIO.read(new File(args[0])); 37 | System.out.println("Loading NN...."); 38 | File NNetwork = new File(args[1]); 39 | if (!NNetwork.exists()) { 40 | System.err.println("Cant Find NN"); 41 | return; 42 | } 43 | nnet = NeuralNetwork.load(new FileInputStream(NNetwork)); // load trained neural network saved with Neuroph Studio 44 | System.out.println("Load Image Recog Plugin...."); 45 | imageRecognition = (ImageRecognitionPlugin) nnet.getPlugin(ImageRecognitionPlugin.class); // get the image recognition plugin from neural network 46 | System.out.println("Recognize Image...."); 47 | HashMap output = imageRecognition.recognizeImage(image); 48 | System.out.println("Output is...."); 49 | System.out.println(output.toString()); 50 | } catch (IOException ex) { 51 | Logger.getLogger(NeuralNetProcessor.class.getName()).log(Level.SEVERE, null, ex); 52 | } 53 | } 54 | 55 | public NeuralNetProcessor(BufferedImage image) { 56 | this.image = image; 57 | } 58 | 59 | void notifyUser() { 60 | Platform.runLater(new Runnable() { 61 | @Override 62 | public void run() { 63 | Alert alert = new Alert(AlertType.ERROR); 64 | alert.setTitle("Neural Network Missing"); 65 | alert.setHeaderText("Cant find network file"); 66 | alert.setContentText("Please make sure that the file " + ConstantObjects.neuralNetworkPath + " exists"); 67 | alert.showAndWait(); 68 | } 69 | }); 70 | } 71 | 72 | @Override 73 | public void doRun() { 74 | try { 75 | //Bypass network reload during comeback through home button 76 | if (nnet == null) { 77 | File NNetwork = new File(ConstantObjects.neuralNetworkPath); 78 | System.out.println("Nueral network loaded = " + NNetwork.getAbsolutePath()); 79 | if (!NNetwork.exists()) { 80 | notifyUser(); 81 | return; 82 | } 83 | nnet = NeuralNetwork.load(new FileInputStream(NNetwork)); // load trained neural network saved with Neuroph Studio 84 | System.out.println("Learning Rule = " + nnet.getLearningRule()); 85 | imageRecognition = (ImageRecognitionPlugin) nnet.getPlugin(ImageRecognitionPlugin.class); // get the image recognition plugin from neural network 86 | } 87 | HashMap output = imageRecognition.recognizeImage(image); 88 | if (output == null) { 89 | System.err.println("Image Recognition Failed"); 90 | } 91 | System.out.println(output.toString()); 92 | listener.neuralnetProcessCompleted(output); 93 | 94 | } catch (Exception ex) { 95 | Logger.getLogger(NeuralNetProcessor.class.getName()).log(Level.SEVERE, null, ex); 96 | listener.neuralnetProcessCompleted(null); 97 | } 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/core/tester/BatchImageTestProcessor.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.core.tester; 2 | 3 | import com.gc.fakeimagedetection.core.listener.BatchImageTestingListener; 4 | import com.gc.fakeimagedetection.ui.alert.Calert; 5 | import java.io.File; 6 | import java.io.FileInputStream; 7 | import java.io.FileNotFoundException; 8 | import java.util.HashMap; 9 | import javafx.scene.control.Alert; 10 | import javax.imageio.ImageIO; 11 | import org.neuroph.core.NeuralNetwork; 12 | import org.neuroph.imgrec.ImageRecognitionPlugin; 13 | 14 | public class BatchImageTestProcessor implements Runnable { 15 | 16 | private int counter = 0; 17 | private int fullSuccess = 0; 18 | private int halfSuccess = 0; 19 | private int error = 0; 20 | private double meanSquareError = 0; 21 | private final File nueralNetwork, realDir, fakeDir; 22 | BatchImageTestingListener listener; 23 | 24 | public BatchImageTestProcessor(File nueralNetwork, File realDir, File fakeDir) { 25 | this.nueralNetwork = nueralNetwork; 26 | this.realDir = realDir; 27 | this.fakeDir = fakeDir; 28 | } 29 | 30 | public void setListener(BatchImageTestingListener listener) { 31 | this.listener = listener; 32 | } 33 | 34 | @Override 35 | public void run() { 36 | if (realDir == null || nueralNetwork == null || fakeDir == null) { 37 | Calert.showAlert("Invalid Data", "Select Required Files", Alert.AlertType.ERROR); 38 | return; 39 | } 40 | 41 | //Load Neural Network 42 | NeuralNetwork network = null; 43 | try { 44 | network = NeuralNetwork.load(new FileInputStream(nueralNetwork)); // load trained neural network saved with Neuroph Studio 45 | } catch (FileNotFoundException ex) { 46 | System.err.println("Neural network failed to load"); 47 | return; 48 | } 49 | System.out.println("Learning Rule = " + network.getLearningRule()); 50 | ImageRecognitionPlugin imageRecognition = (ImageRecognitionPlugin) network.getPlugin(ImageRecognitionPlugin.class); // get the 51 | 52 | //Test Fake Images 53 | for (File fakeImage : fakeDir.listFiles()) { 54 | HashMap output; 55 | try { 56 | output = imageRecognition.recognizeImage(ImageIO.read(fakeImage)); 57 | } catch (Exception ex) { 58 | System.err.println("Image Failed to load" + fakeImage.getAbsolutePath() + ex.getMessage()); 59 | continue; 60 | } 61 | if (output == null) { 62 | System.err.println("Image Recognition Failed"); 63 | continue; 64 | } 65 | counter++; 66 | double real = output.get("real"); 67 | double fake = output.get("faked"); 68 | if (fake >= 0.9 && real < 0.1) { 69 | fullSuccess++; 70 | System.out.println("Required Out : Fake = 1, Real = 0 :: Output Fake = " + fake + " | Real = " + real); 71 | } else if (fake > 0.7) { 72 | halfSuccess++; 73 | System.out.println("Required Out : Fake = 1, Real = 0 :: Output Fake = " + fake + " | Real = " + real); 74 | } else { 75 | System.err.println("Required Out : Fake = 1, Real = 0 :: Output Fake = " + fake + " | Real = " + real + fakeImage.getName()); 76 | } 77 | if (fake < 0.8) { 78 | error++; 79 | } 80 | meanSquareError += ((1 - fake) * (1 - fake)); 81 | } 82 | 83 | //Test Real Images 84 | for (File realImage : realDir.listFiles()) { 85 | HashMap output; 86 | try { 87 | output = imageRecognition.recognizeImage(ImageIO.read(realImage)); 88 | } catch (Exception ex) { 89 | System.err.println("Image Failed to Load " + realImage.getAbsolutePath() + ex.getLocalizedMessage()); 90 | continue; 91 | } 92 | if (output == null) { 93 | System.err.println("Image Recognition Failed"); 94 | continue; 95 | } 96 | counter++; 97 | double real = output.get("real"); 98 | double fake = output.get("faked"); 99 | if (real >= 0.9 && fake < 0.1) { 100 | fullSuccess++; 101 | System.out.println("Required Out : Fake = 0, Real = 1 :: Output Fake = " + fake + " | Real = " + real); 102 | } else if (real > 0.8) { 103 | halfSuccess++; 104 | System.out.println("Required Out : Fake = 0, Real = 1 :: Output Fake = " + fake + " | Real = " + real); 105 | } else { 106 | System.err.println("Required Out : Fake = 0, Real = 1 :: Output Fake = " + fake + " | Real = " + real + realImage.getName()); 107 | } 108 | if (real < 0.8) { 109 | error++; 110 | } 111 | meanSquareError += ((1 - real) * (1 - real)); 112 | } 113 | meanSquareError = meanSquareError / counter; 114 | 115 | String result = ""; 116 | result += ("\n-------------------------------------------------------------------"); 117 | result += ("\nNumber of image processed = " + counter); 118 | result += ("\n100% Correct Detection = " + fullSuccess); 119 | result += ("\nAmbigious Correct Detection = " + halfSuccess); 120 | result += ("\nTotal Error = " + error); 121 | result += ("\nMean Square Error = " + meanSquareError); 122 | result += ("\n-------------------------------------------------------------------"); 123 | System.out.println(result); 124 | listener.testingComplete(result); 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/core/trainer/BatchImageTrainer.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.core.trainer; 2 | 3 | import com.gc.fakeimagedetection.core.listener.BatchImageTrainingListener; 4 | import com.gc.fakeimagedetection.core.multithread.NotifyingThread; 5 | import com.gc.fakeimagedetection.ui.alert.Calert; 6 | import java.awt.Dimension; 7 | import java.awt.image.BufferedImage; 8 | import java.io.File; 9 | import java.io.FileInputStream; 10 | import java.io.FileNotFoundException; 11 | import java.util.ArrayList; 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | import javafx.fxml.FXMLLoader; 15 | import javafx.scene.Parent; 16 | import javafx.scene.Scene; 17 | import javafx.scene.control.Alert; 18 | import javafx.stage.Stage; 19 | import org.apache.commons.io.FilenameUtils; 20 | import org.neuroph.core.NeuralNetwork; 21 | import org.neuroph.core.data.DataSet; 22 | import org.neuroph.core.events.LearningEvent; 23 | import org.neuroph.core.events.LearningEventListener; 24 | import org.neuroph.imgrec.FractionRgbData; 25 | import org.neuroph.imgrec.ImageRecognitionHelper; 26 | import org.neuroph.imgrec.ImageUtilities; 27 | import org.neuroph.nnet.learning.BackPropagation; 28 | import org.neuroph.nnet.learning.MomentumBackpropagation; 29 | 30 | public class BatchImageTrainer extends NotifyingThread implements LearningEventListener { 31 | 32 | File srcDirectory; 33 | File nnFile; 34 | Dimension sampleDimension; 35 | ArrayList imageLabels; 36 | NeuralNetwork nnet; 37 | float learningRate = 0f; 38 | float momentum = 0f; 39 | float maxError = 0f; 40 | BatchImageTrainingListener listener; 41 | 42 | public BatchImageTrainer(File srcDirectory, 43 | File nnFile, 44 | Dimension sampleDimension, 45 | ArrayList imageLabels, 46 | BatchImageTrainingListener listener) { 47 | this.srcDirectory = srcDirectory; 48 | this.sampleDimension = sampleDimension; 49 | this.imageLabels = imageLabels; 50 | this.listener = listener; 51 | this.nnFile = nnFile; 52 | } 53 | 54 | public void setMomentum(float momentum) { 55 | this.momentum = momentum; 56 | } 57 | 58 | public void setLearningRate(float learningRate) { 59 | this.learningRate = learningRate; 60 | } 61 | 62 | public void setMaxError(float maxError) { 63 | this.maxError = maxError; 64 | } 65 | 66 | public void stopLearning() { 67 | try { 68 | nnet.stopLearning(); 69 | } catch (Exception e) { 70 | System.out.println(e.getMessage()); 71 | } 72 | } 73 | 74 | public void saveLearnedNetwork(String path) { 75 | try { 76 | nnet.save(path); 77 | Calert.showAlert("Saved", "Neural network saved" + path, Alert.AlertType.INFORMATION); 78 | } catch (Exception e) { 79 | System.err.println("Failed"); 80 | } 81 | } 82 | 83 | @Override 84 | public void doRun() { 85 | try { 86 | System.out.println("Starting training thread....." + sampleDimension.toString() + " and " + imageLabels.toString()); 87 | 88 | HashMap imagesMap = new HashMap(); 89 | for (File file : srcDirectory.listFiles()) { 90 | imageLabels.add(FilenameUtils.removeExtension(file.getName())); 91 | if (sampleDimension.getWidth() > 0 && sampleDimension.getHeight() > 0) { 92 | Double w = sampleDimension.getWidth(); 93 | Double h = sampleDimension.getHeight(); 94 | imagesMap.put(file.getName(), ImageUtilities.resizeImage(ImageUtilities.loadImage(file), w.intValue(), h.intValue())); 95 | } 96 | } 97 | Map imageRgbData = ImageUtilities.getFractionRgbDataForImages(imagesMap); 98 | DataSet learningData = ImageRecognitionHelper.createRGBTrainingSet(imageLabels, imageRgbData); 99 | 100 | nnet = NeuralNetwork.load(new FileInputStream(nnFile)); //Load NNetwork 101 | MomentumBackpropagation mBackpropagation = (MomentumBackpropagation) nnet.getLearningRule(); 102 | mBackpropagation.setLearningRate(learningRate); 103 | mBackpropagation.setMaxError(maxError); 104 | mBackpropagation.setMomentum(momentum); 105 | 106 | System.out.println("Network Information\nLabel = " + nnet.getLabel() 107 | + "\n Input Neurons = " + nnet.getInputsCount() 108 | + "\n Number of layers = " + nnet.getLayersCount() 109 | ); 110 | 111 | mBackpropagation.addListener(this); 112 | System.out.println("Starting training......"); 113 | nnet.learn(learningData, mBackpropagation); 114 | //Training Completed 115 | listener.batchImageTrainingCompleted(); 116 | } catch (FileNotFoundException ex) { 117 | System.out.println(ex.getMessage() + "\n" + ex.getLocalizedMessage()); 118 | } 119 | 120 | } 121 | 122 | @Override 123 | public void handleLearningEvent(LearningEvent event) { 124 | BackPropagation bp = (BackPropagation) event.getSource(); 125 | System.out.println(bp.getCurrentIteration() + ". iteration | Total network error: " + bp.getTotalNetworkError()); 126 | listener.batchImageTrainingUpdate(bp.getCurrentIteration(), bp.getTotalNetworkError()); 127 | } 128 | 129 | private void loadGraph() { 130 | try { 131 | FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/resources/fxml/training_display.fxml")); 132 | Parent root1 = (Parent) fxmlLoader.load(); 133 | Stage stage = new Stage(); 134 | stage.setTitle("Graph View"); 135 | stage.setScene(new Scene(root1)); 136 | stage.show(); 137 | } catch (Exception e) { 138 | System.err.println(e.getMessage()); 139 | } 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/core/trainer/SingleImageTrainer.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.core.trainer; 2 | 3 | import com.gc.fakeimagedetection.core.constants.ConstantObjects; 4 | import com.gc.fakeimagedetection.core.processor.NeuralNetProcessor; 5 | import com.gc.fakeimagedetection.core.multithread.NotifyingThread; 6 | import java.awt.image.BufferedImage; 7 | import java.util.ArrayList; 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | import org.neuroph.core.NeuralNetwork; 11 | import org.neuroph.core.data.DataSet; 12 | import org.neuroph.core.events.LearningEvent; 13 | import org.neuroph.core.events.LearningEventListener; 14 | import org.neuroph.imgrec.FractionRgbData; 15 | import org.neuroph.imgrec.ImageRecognitionHelper; 16 | import org.neuroph.imgrec.ImageUtilities; 17 | import org.neuroph.nnet.learning.BackPropagation; 18 | import org.neuroph.nnet.learning.MomentumBackpropagation; 19 | 20 | public class SingleImageTrainer extends NotifyingThread implements LearningEventListener { 21 | 22 | NeuralNetwork nnet; 23 | BufferedImage image; 24 | Boolean isReal; 25 | ArrayList labels; 26 | float learningRate = 0.2f; 27 | float maxError = 0.01f; 28 | float momentum = 0.6f; 29 | public static Boolean isDirty = false; 30 | 31 | public SingleImageTrainer(NeuralNetwork nnet, BufferedImage image, Boolean isReal) { 32 | this.nnet = nnet; 33 | this.image = image; 34 | this.isReal = isReal; 35 | labels = new ArrayList<>(); 36 | labels.add("real"); 37 | labels.add("faked"); 38 | } 39 | 40 | @Override 41 | public void doRun() { 42 | HashMap imagesMap = new HashMap(); 43 | String fileName = ""; 44 | if (!isReal) { 45 | fileName = "real"; 46 | } else { 47 | fileName = "faked"; 48 | } 49 | 50 | System.out.println("Teaching as " + fileName); 51 | imagesMap.put(fileName, image); 52 | Map imageRgbData = ImageUtilities.getFractionRgbDataForImages(imagesMap); 53 | DataSet learningData = ImageRecognitionHelper.createRGBTrainingSet(labels, imageRgbData); 54 | MomentumBackpropagation mBackpropagation = (MomentumBackpropagation) nnet.getLearningRule(); 55 | mBackpropagation.setLearningRate(learningRate); 56 | mBackpropagation.setMaxError(maxError); 57 | mBackpropagation.setMomentum(momentum); 58 | 59 | System.out.println("Network Information\nLabel = " + nnet.getLabel() 60 | + "\n Input Neurons = " + nnet.getInputsCount() 61 | + "\n Number of layers = " + nnet.getLayersCount() 62 | ); 63 | 64 | mBackpropagation.addListener(this); 65 | System.out.println("Starting training......"); 66 | nnet.learn(learningData, mBackpropagation); 67 | 68 | //Mark nnet as dirty. Write on close 69 | isDirty = true; 70 | } 71 | 72 | @Override 73 | public void handleLearningEvent(LearningEvent event) { 74 | BackPropagation bp = (BackPropagation) event.getSource(); 75 | System.out.println(bp.getCurrentIteration() + ". iteration | Total network error: " + bp.getTotalNetworkError()); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/ui/BatchImageTester.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.ui; 2 | 3 | import com.gc.fakeimagedetection.ui.alert.CommonUtil; 4 | import javafx.application.Application; 5 | import static javafx.application.Application.launch; 6 | import javafx.fxml.FXMLLoader; 7 | import javafx.scene.Parent; 8 | import javafx.scene.Scene; 9 | import javafx.stage.Stage; 10 | import static javafx.application.Application.launch; 11 | 12 | public class BatchImageTester extends Application { 13 | 14 | @Override 15 | public void start(Stage stage) throws Exception { 16 | Parent root = FXMLLoader.load(getClass().getResource("/resources/fxml/batchimagetester.fxml")); 17 | 18 | Scene scene = new Scene(root); 19 | 20 | stage.resizableProperty().setValue(false); 21 | stage.setTitle("Batch Image Tester"); 22 | stage.setScene(scene); 23 | CommonUtil.attachIcon(stage); 24 | stage.show(); 25 | } 26 | 27 | public static void main(String[] args) { 28 | launch(args); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/ui/ELABatchImageProcessor.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.ui; 2 | 3 | import com.gc.fakeimagedetection.ui.alert.CommonUtil; 4 | import javafx.application.Application; 5 | import javafx.fxml.FXMLLoader; 6 | import javafx.scene.Parent; 7 | import javafx.scene.Scene; 8 | import javafx.stage.Stage; 9 | import static javafx.application.Application.launch; 10 | 11 | public class ELABatchImageProcessor extends Application { 12 | 13 | @Override 14 | public void start(Stage stage) throws Exception { 15 | Parent root = FXMLLoader.load(getClass().getResource("/resources/fxml/batchimageprocessor.fxml")); 16 | 17 | Scene scene = new Scene(root); 18 | 19 | stage.resizableProperty().setValue(false); 20 | stage.setTitle("Batch ELA processor"); 21 | stage.setScene(scene); 22 | CommonUtil.attachIcon(stage); 23 | stage.show(); 24 | } 25 | 26 | public static void main(String[] args) { 27 | launch(args); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/ui/Main.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.ui; 2 | 3 | import com.gc.fakeimagedetection.core.constants.ConstantObjects; 4 | import com.gc.fakeimagedetection.core.processor.NeuralNetProcessor; 5 | import com.gc.fakeimagedetection.core.trainer.SingleImageTrainer; 6 | import com.gc.fakeimagedetection.ui.alert.CommonUtil; 7 | import java.util.Optional; 8 | import javafx.application.Application; 9 | import javafx.fxml.FXMLLoader; 10 | import javafx.scene.Parent; 11 | import javafx.scene.Scene; 12 | import javafx.scene.control.Alert; 13 | import javafx.scene.control.Alert.AlertType; 14 | import javafx.scene.control.ButtonType; 15 | import javafx.scene.image.Image; 16 | import javafx.stage.Stage; 17 | import javafx.stage.WindowEvent; 18 | 19 | public class Main extends Application { 20 | 21 | @Override 22 | public void start(Stage stage) throws Exception { 23 | Parent root = FXMLLoader.load(getClass().getResource("/resources/fxml/launch.fxml")); 24 | 25 | Scene scene = new Scene(root); 26 | 27 | stage.setTitle("Christopher"); 28 | stage.setScene(scene); 29 | stage.show(); 30 | CommonUtil.attachIcon(stage); 31 | stage.setOnCloseRequest((WindowEvent event) -> { 32 | if (SingleImageTrainer.isDirty) { 33 | Alert alert = new Alert(AlertType.CONFIRMATION); 34 | alert.setTitle("Save Changes ?"); 35 | alert.setHeaderText("Neural Network has been updated with new data"); 36 | alert.setContentText("Do you want to save changes ?"); 37 | Optional result = alert.showAndWait(); 38 | if (result.get() == ButtonType.OK) { 39 | NeuralNetProcessor.nnet.save(ConstantObjects.neuralNetworkPath); 40 | System.out.println("Saved to " + ConstantObjects.neuralNetworkPath); 41 | System.exit(0); 42 | } else { 43 | System.out.println("Changes discared"); 44 | System.exit(1); 45 | } 46 | } 47 | }); 48 | } 49 | 50 | public static void main(String[] args) { 51 | launch(args); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/ui/NeuralNetCreator.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.ui; 2 | 3 | import com.gc.fakeimagedetection.ui.alert.CommonUtil; 4 | import javafx.application.Application; 5 | import javafx.fxml.FXMLLoader; 6 | import javafx.scene.Parent; 7 | import javafx.scene.Scene; 8 | import javafx.stage.Stage; 9 | import javafx.stage.WindowEvent; 10 | import static javafx.application.Application.launch; 11 | 12 | public class NeuralNetCreator extends Application { 13 | 14 | @Override 15 | public void start(Stage stage) throws Exception { 16 | Parent root = FXMLLoader.load(getClass().getResource("/resources/fxml/networkcreator.fxml")); 17 | 18 | Scene scene = new Scene(root); 19 | 20 | stage.resizableProperty().setValue(false); 21 | stage.setTitle("Neural Network Creator"); 22 | stage.setScene(scene); 23 | stage.show(); 24 | CommonUtil.attachIcon(stage); 25 | 26 | stage.setOnCloseRequest((WindowEvent event) -> { 27 | System.exit(0); 28 | }); 29 | } 30 | 31 | public static void main(String[] args) { 32 | launch(args); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/ui/SingleImageCheck.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.ui; 2 | 3 | import com.gc.fakeimagedetection.ui.alert.CommonUtil; 4 | import javafx.application.Application; 5 | import static javafx.application.Application.launch; 6 | import javafx.fxml.FXMLLoader; 7 | import javafx.scene.Parent; 8 | import javafx.scene.Scene; 9 | import javafx.stage.Stage; 10 | import javafx.stage.WindowEvent; 11 | import static javafx.application.Application.launch; 12 | 13 | public class SingleImageCheck extends Application { 14 | 15 | @Override 16 | public void start(Stage stage) throws Exception { 17 | Parent root = FXMLLoader.load(getClass().getResource("/resources/fxml/singleimage.fxml")); 18 | 19 | Scene scene = new Scene(root); 20 | 21 | stage.resizableProperty().setValue(false); 22 | stage.setTitle("Single Image Checker"); 23 | stage.setScene(scene); 24 | stage.show(); 25 | CommonUtil.attachIcon(stage); 26 | 27 | stage.setOnCloseRequest((WindowEvent event) -> { 28 | System.exit(0); 29 | }); 30 | } 31 | 32 | public static void main(String[] args) { 33 | launch(args); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/ui/TrainerMain.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.ui; 2 | 3 | import com.gc.fakeimagedetection.ui.alert.CommonUtil; 4 | import javafx.application.Application; 5 | import javafx.fxml.FXMLLoader; 6 | import javafx.scene.Parent; 7 | import javafx.scene.Scene; 8 | import javafx.stage.Stage; 9 | import javafx.stage.WindowEvent; 10 | import static javafx.application.Application.launch; 11 | 12 | public class TrainerMain extends Application { 13 | 14 | @Override 15 | public void start(Stage stage) throws Exception { 16 | Parent root = FXMLLoader.load(getClass().getResource("/resources/fxml/traininginterface.fxml")); 17 | 18 | Scene scene = new Scene(root); 19 | 20 | stage.resizableProperty().setValue(false); 21 | stage.setTitle("Network Trainer"); 22 | stage.setScene(scene); 23 | stage.show(); 24 | CommonUtil.attachIcon(stage); 25 | 26 | stage.setOnCloseRequest((WindowEvent event) -> { 27 | System.exit(0); 28 | }); 29 | } 30 | 31 | public static void main(String[] args) { 32 | launch(args); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/ui/alert/Calert.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.ui.alert; 2 | 3 | import javafx.scene.control.Alert; 4 | 5 | public class Calert { 6 | 7 | public static void showAlert(String title, String Content, Alert.AlertType alertType) { 8 | Alert alert = new Alert(alertType); 9 | alert.setTitle(title); 10 | alert.setHeaderText(null); 11 | alert.setContentText(Content); 12 | alert.showAndWait(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/ui/alert/CommonUtil.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.ui.alert; 2 | 3 | import com.gc.fakeimagedetection.ui.Main; 4 | import javafx.scene.image.Image; 5 | import javafx.stage.Stage; 6 | 7 | public class CommonUtil { 8 | 9 | private static final String ICON = "/resources/icon/icon.png"; 10 | 11 | public static void attachIcon(Stage stage) { 12 | stage.getIcons().add(new Image(Main.class.getResourceAsStream(ICON))); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/ui/controllers/BatchImageProcessorController.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.ui.controllers; 2 | 3 | import com.jfoenix.controls.JFXCheckBox; 4 | import com.jfoenix.controls.JFXTextField; 5 | import com.gc.fakeimagedetection.ui.alert.Calert; 6 | import com.gc.fakeimagedetection.core.errorlevelanalysis.ImageStandardizer; 7 | import com.gc.fakeimagedetection.core.listener.ErrorLevelAnalysisUpdateListener; 8 | import java.awt.Dimension; 9 | import java.io.File; 10 | import java.net.URL; 11 | import java.util.ResourceBundle; 12 | import javafx.event.ActionEvent; 13 | import javafx.fxml.FXML; 14 | import javafx.fxml.Initializable; 15 | import javafx.scene.control.Alert; 16 | import javafx.scene.control.ProgressBar; 17 | import javafx.scene.layout.AnchorPane; 18 | import javafx.scene.text.Text; 19 | import javafx.stage.DirectoryChooser; 20 | 21 | public class BatchImageProcessorController implements Initializable, ErrorLevelAnalysisUpdateListener { 22 | 23 | @FXML 24 | private JFXCheckBox srcIndicator; 25 | @FXML 26 | private JFXTextField sWidth; 27 | @FXML 28 | private JFXTextField sHeight; 29 | @FXML 30 | private JFXTextField outputBatchName; 31 | @FXML 32 | private JFXCheckBox destIndicator; 33 | @FXML 34 | private ProgressBar progressBar; 35 | 36 | File srcDir = null; 37 | File destDir = null; 38 | @FXML 39 | private AnchorPane rootPane; 40 | 41 | private String bName = "real_"; 42 | @FXML 43 | private Text status; 44 | 45 | @Override 46 | public void initialize(URL url, ResourceBundle rb) { 47 | } 48 | 49 | @FXML 50 | private void loadSourceFolder(ActionEvent event) { 51 | DirectoryChooser chooser = new DirectoryChooser(); 52 | chooser.setTitle("Choose Source Folder"); 53 | srcDir = chooser.showDialog(rootPane.getScene().getWindow()); 54 | if (srcDir == null) { 55 | Calert.showAlert("Error", "Not a valid folder", Alert.AlertType.ERROR); 56 | return; 57 | } 58 | srcIndicator.setSelected(true); 59 | } 60 | 61 | @FXML 62 | private void loadDestinationFolder(ActionEvent event) { 63 | DirectoryChooser chooser = new DirectoryChooser(); 64 | chooser.setTitle("Choose Source Folder"); 65 | destDir = chooser.showDialog(rootPane.getScene().getWindow()); 66 | if (destDir == null) { 67 | Calert.showAlert("Error", "Not a valid folder", Alert.AlertType.ERROR); 68 | return; 69 | } 70 | destIndicator.setSelected(true); 71 | } 72 | 73 | @FXML 74 | private void startProcessing(ActionEvent event) { 75 | int width = Integer.parseInt(sWidth.getText()); 76 | int height = Integer.parseInt(sHeight.getText()); 77 | bName = outputBatchName.getText(); 78 | if (srcDir != null && destDir != null) { 79 | ImageStandardizer ims = new ImageStandardizer(srcDir, destDir, new Dimension(width, height), bName); 80 | ims.setListener(this); 81 | ims.run(); 82 | } else { 83 | System.out.println("Source Not selected"); 84 | } 85 | } 86 | 87 | @Override 88 | public void iterationCompleted(String data, Float percentage) { 89 | status.setText(data); 90 | progressBar.setProgress(percentage); 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/ui/controllers/BatchImageTesterController.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.ui.controllers; 2 | 3 | import com.jfoenix.controls.JFXButton; 4 | import com.jfoenix.controls.JFXCheckBox; 5 | import com.jfoenix.controls.JFXSpinner; 6 | import com.gc.fakeimagedetection.core.listener.BatchImageTestingListener; 7 | import com.gc.fakeimagedetection.core.tester.BatchImageTestProcessor; 8 | import com.gc.fakeimagedetection.ui.alert.Calert; 9 | import java.io.File; 10 | import java.net.URL; 11 | import java.util.ResourceBundle; 12 | import javafx.application.Platform; 13 | import javafx.event.ActionEvent; 14 | import javafx.fxml.FXML; 15 | import javafx.fxml.Initializable; 16 | import javafx.scene.control.Alert; 17 | import javafx.scene.layout.AnchorPane; 18 | import javafx.stage.DirectoryChooser; 19 | import javafx.stage.FileChooser; 20 | 21 | public class BatchImageTesterController implements Initializable, BatchImageTestingListener { 22 | 23 | @FXML 24 | private JFXCheckBox neuralIndicator; 25 | @FXML 26 | private JFXCheckBox realIndicator; 27 | @FXML 28 | private JFXCheckBox fakeIndicator; 29 | @FXML 30 | private AnchorPane rootPane; 31 | @FXML 32 | private JFXButton startButton; 33 | 34 | File neuralNetwork; 35 | File realDir; 36 | File fakeDir; 37 | @FXML 38 | private JFXSpinner spinner; 39 | 40 | @Override 41 | public void initialize(URL url, ResourceBundle rb) { 42 | spinner.setVisible(false); 43 | } 44 | 45 | @FXML 46 | private void chooseNeuralNetwork(ActionEvent event) { 47 | FileChooser chooser = new FileChooser(); 48 | chooser.setTitle("Choose Neuralnet"); 49 | neuralNetwork = chooser.showOpenDialog(rootPane.getScene().getWindow()); 50 | if (neuralNetwork == null) { 51 | Calert.showAlert("Error", "Not a valid neural network", Alert.AlertType.ERROR); 52 | return; 53 | } 54 | 55 | System.out.println("Loading Neuralnet from " + neuralNetwork.getAbsolutePath()); 56 | neuralIndicator.setSelected(true); 57 | } 58 | 59 | @FXML 60 | private void chooseRealImageSource(ActionEvent event) { 61 | DirectoryChooser chooser = new DirectoryChooser(); 62 | chooser.setTitle("Choose Real Image Folder"); 63 | realDir = chooser.showDialog(rootPane.getScene().getWindow()); 64 | if (realDir == null) { 65 | Calert.showAlert("Error", "Not a valid directory", Alert.AlertType.ERROR); 66 | return; 67 | } 68 | 69 | System.out.println("Loading Real Images from " + realDir.getAbsolutePath()); 70 | realIndicator.setSelected(true); 71 | } 72 | 73 | @FXML 74 | private void chooseFakeImageSource(ActionEvent event) { 75 | DirectoryChooser chooser = new DirectoryChooser(); 76 | chooser.setTitle("Choose Fake Image Folder"); 77 | fakeDir = chooser.showDialog(rootPane.getScene().getWindow()); 78 | if (fakeDir == null) { 79 | Calert.showAlert("Error", "Not a valid directory", Alert.AlertType.ERROR); 80 | return; 81 | } 82 | 83 | System.out.println("Loading Fake Images from " + realDir.getAbsolutePath()); 84 | fakeIndicator.setSelected(true); 85 | } 86 | 87 | @FXML 88 | private void startTesting(ActionEvent event) { 89 | startButton.setText("Running..."); 90 | BatchImageTestProcessor processor = new BatchImageTestProcessor(neuralNetwork, realDir, fakeDir); 91 | processor.setListener(this); 92 | Thread runnerThread = new Thread(processor); 93 | runnerThread.start(); 94 | spinner.setVisible(true); 95 | } 96 | 97 | void updateText(String text) { 98 | Platform.runLater(new Runnable() { 99 | @Override 100 | public void run() { 101 | startButton.setText(text); 102 | } 103 | }); 104 | } 105 | 106 | void showResult(String result) { 107 | Platform.runLater(new Runnable() { 108 | @Override 109 | public void run() { 110 | Calert.showAlert("Result", result, Alert.AlertType.INFORMATION); 111 | } 112 | }); 113 | } 114 | 115 | @Override 116 | public void testingComplete(String result) { 117 | spinner.setVisible(false); 118 | showResult(result); 119 | updateText("Completed"); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/ui/controllers/LaunchScreeenController.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.ui.controllers; 2 | 3 | import com.jfoenix.controls.JFXButton; 4 | import com.gc.fakeimagedetection.core.constants.ConstantObjects; 5 | import com.gc.fakeimagedetection.ui.alert.Calert; 6 | import com.gc.fakeimagedetection.core.metadata.MetadataProcessor; 7 | import com.gc.fakeimagedetection.ui.BatchImageTester; 8 | import com.gc.fakeimagedetection.ui.ELABatchImageProcessor; 9 | import com.gc.fakeimagedetection.ui.SingleImageCheck; 10 | import com.gc.fakeimagedetection.ui.TrainerMain; 11 | import java.io.File; 12 | import java.io.FileInputStream; 13 | import java.io.IOException; 14 | import java.net.URL; 15 | import java.util.ResourceBundle; 16 | import java.util.logging.Level; 17 | import java.util.logging.Logger; 18 | import javafx.animation.KeyFrame; 19 | import javafx.animation.KeyValue; 20 | import javafx.animation.ParallelTransition; 21 | import javafx.animation.ScaleTransition; 22 | import javafx.animation.Timeline; 23 | import javafx.animation.TranslateTransition; 24 | import javafx.event.ActionEvent; 25 | import javafx.fxml.FXML; 26 | import javafx.fxml.FXMLLoader; 27 | import javafx.fxml.Initializable; 28 | import javafx.scene.control.Alert.AlertType; 29 | import javafx.scene.control.CheckMenuItem; 30 | import javafx.scene.image.Image; 31 | import javafx.scene.image.ImageView; 32 | import javafx.scene.input.MouseEvent; 33 | import javafx.scene.layout.AnchorPane; 34 | import javafx.scene.layout.BorderPane; 35 | import javafx.scene.layout.StackPane; 36 | import javafx.scene.text.Font; 37 | import javafx.scene.text.FontWeight; 38 | import javafx.scene.text.Text; 39 | import javafx.stage.FileChooser; 40 | import javafx.stage.Modality; 41 | import javafx.stage.Stage; 42 | import javafx.stage.WindowEvent; 43 | import javafx.util.Duration; 44 | 45 | public class LaunchScreeenController implements Initializable { 46 | 47 | @FXML 48 | private JFXButton load_image_button; 49 | 50 | @FXML 51 | private Text christopher; 52 | 53 | @FXML 54 | private StackPane rootPane; 55 | 56 | @FXML 57 | private Text description; 58 | 59 | @FXML 60 | private AnchorPane anchorPane; 61 | 62 | @FXML 63 | private ImageView homeIcon; 64 | @FXML 65 | private ImageView backgroundImageView; 66 | 67 | int duration = 1500; 68 | FileChooser fileChooser; 69 | Boolean isFirstTime = true; 70 | ScaleTransition bulgingTransition; 71 | ParallelTransition buttonParallelTransition; 72 | public static File processingFile = null; 73 | public static StackPane parentPaneForAll; 74 | @FXML 75 | private CheckMenuItem resultPropogation; 76 | 77 | @Override 78 | public void initialize(URL url, ResourceBundle rb) { 79 | parentPaneForAll = rootPane; 80 | 81 | } 82 | 83 | private void animate() { 84 | TranslateTransition tt = new TranslateTransition(Duration.millis(duration), load_image_button); 85 | TranslateTransition tLogo = new TranslateTransition(Duration.millis(duration), christopher); 86 | TranslateTransition tDesc = new TranslateTransition(Duration.millis(duration), description); 87 | 88 | ScaleTransition st = new ScaleTransition(Duration.millis(duration), load_image_button); 89 | st.setToX(3); 90 | st.setToY(3); 91 | 92 | tt.setByY(-180f); 93 | 94 | tLogo.setToY(50); 95 | tDesc.setToY(500); 96 | buttonParallelTransition = new ParallelTransition(load_image_button, st, tt, tLogo, tDesc); 97 | 98 | buttonParallelTransition.play(); 99 | buttonParallelTransition.setOnFinished((e) -> { 100 | load_image_button.setOpacity(1); 101 | }); 102 | } 103 | 104 | @FXML 105 | private void loadAnimation(MouseEvent event) { 106 | if (isFirstTime) { 107 | animate(); 108 | isFirstTime = false; 109 | } 110 | } 111 | 112 | @FXML 113 | void loadImageSelector(ActionEvent event) { 114 | if (processingFile != null) { 115 | return; 116 | } 117 | fileChooser = new FileChooser(); 118 | configureFileChooser(fileChooser); 119 | fileChooser.setTitle("Open Resource File"); 120 | processingFile = fileChooser.showOpenDialog(rootPane.getScene().getWindow()); 121 | if (processingFile == null) { 122 | Calert.showAlert("No File Selected", "You haven't selected any images", AlertType.ERROR); 123 | return; 124 | } 125 | 126 | try { 127 | backgroundImageView.setImage(new Image(new FileInputStream(processingFile))); 128 | backgroundImageView.setOpacity(0.5); 129 | } catch (Exception ex) { 130 | Logger.getLogger(LaunchScreeenController.class.getName()).log(Level.SEVERE, null, ex); 131 | } 132 | removeBannersandDescs(); 133 | loadMetaDataCheck(); 134 | } 135 | 136 | private static void configureFileChooser(final FileChooser fileChooser) { 137 | fileChooser.setTitle("View Pictures"); 138 | fileChooser.setInitialDirectory( 139 | new File(System.getProperty("user.dir")) 140 | ); 141 | FileChooser.ExtensionFilter extFilter 142 | = new FileChooser.ExtensionFilter("Image Files", "*.JPG", "*.jpg", "*.jpeg", "*.JPEG"); 143 | fileChooser.getExtensionFilters().addAll(extFilter 144 | ); 145 | 146 | } 147 | 148 | private void removeBannersandDescs() { 149 | TranslateTransition tChristopher = new TranslateTransition(Duration.millis(duration), christopher); 150 | TranslateTransition tDescription = new TranslateTransition(Duration.millis(duration), description); 151 | tChristopher.setToY(-200); 152 | tDescription.setToY(1000); 153 | ParallelTransition pt = new ParallelTransition(tChristopher, tDescription); 154 | pt.play(); 155 | 156 | } 157 | 158 | private void loadMetaDataCheck() { 159 | startSimpleMetaDataAnimation(); 160 | 161 | MetadataProcessor processor = new MetadataProcessor(processingFile); 162 | 163 | bulgingTransition.setOnFinished((e) -> { 164 | TranslateTransition tt = new TranslateTransition(Duration.millis(duration - 500), load_image_button); 165 | ScaleTransition st = new ScaleTransition(Duration.millis(duration - 500), load_image_button); 166 | st.setToX(1); 167 | st.setToY(1); 168 | 169 | tt.setToX(-150f); 170 | tt.setToY(80f); 171 | 172 | Timeline timeline = new Timeline(); 173 | timeline.setCycleCount(1); 174 | 175 | KeyValue keyValueX = new KeyValue(load_image_button.prefWidthProperty(), 400); 176 | KeyValue keyValueY = new KeyValue(load_image_button.prefHeightProperty(), 50); 177 | KeyFrame keyFrame = new KeyFrame(Duration.millis(duration - 500), keyValueX, keyValueY); 178 | timeline.getKeyFrames().add(keyFrame); 179 | 180 | ParallelTransition pt = new ParallelTransition(load_image_button, st, tt, timeline); 181 | pt.play(); 182 | 183 | pt.setOnFinished((e1) -> { 184 | loadMetadataResult(); 185 | load_image_button.setText("Test On AI"); 186 | load_image_button.setFont(Font.font("Roboto", FontWeight.BOLD, 20)); 187 | homeIcon.setVisible(true); 188 | // Neural Network Entry 189 | load_image_button.setOnMouseClicked((e2) -> { 190 | System.out.println("Loading NN........"); 191 | try { 192 | anchorPane.getChildren().clear(); 193 | StackPane pane = FXMLLoader.load(getClass().getResource("/resources/fxml/neuralinterface.fxml")); 194 | anchorPane.getChildren().setAll(pane); 195 | } catch (IOException ex) { 196 | Logger.getLogger(MetadataResultController.class.getName()).log(Level.SEVERE, null, ex); 197 | } 198 | }); 199 | }); 200 | }); 201 | 202 | } 203 | 204 | private void startSimpleMetaDataAnimation() { 205 | float animationExtension = 3.25f; 206 | bulgingTransition = new ScaleTransition(Duration.millis(1000), load_image_button); 207 | bulgingTransition.setToX(animationExtension); 208 | bulgingTransition.setToY(animationExtension); 209 | bulgingTransition.autoReverseProperty().setValue(true); 210 | bulgingTransition.setCycleCount(2); 211 | bulgingTransition.play(); 212 | load_image_button.setFont(Font.font("Roboto", FontWeight.NORMAL, 8)); 213 | load_image_button.setText("Checking Metadata.."); 214 | 215 | } 216 | 217 | private void loadMetadataResult() { 218 | try { 219 | AnchorPane result = FXMLLoader.load(getClass().getResource("/resources/fxml/metadataresult.fxml")); 220 | anchorPane.getChildren().add(result); 221 | } catch (IOException ex) { 222 | Logger.getLogger(LaunchScreeenController.class.getName()).log(Level.SEVERE, null, ex); 223 | } 224 | } 225 | 226 | @FXML 227 | private void rollBack(MouseEvent event) { 228 | processingFile = null; 229 | try { 230 | BorderPane pane = FXMLLoader.load(getClass().getResource("/resources/fxml/launch.fxml")); 231 | rootPane.getChildren().clear(); 232 | rootPane.getChildren().setAll(pane); 233 | MetadataProcessor.extracted_data = ""; 234 | } catch (IOException ex) { 235 | Logger.getLogger(LaunchScreeenController.class.getName()).log(Level.SEVERE, null, ex); 236 | } 237 | } 238 | 239 | @FXML 240 | private void loadELAProcessor(ActionEvent event) throws Exception { 241 | ELABatchImageProcessor processor = new ELABatchImageProcessor(); 242 | Stage stage = new Stage(); 243 | stage.initOwner(rootPane.getScene().getWindow()); 244 | stage.initModality(Modality.WINDOW_MODAL); 245 | processor.start(stage); 246 | } 247 | 248 | @FXML 249 | private void loadTrainer(ActionEvent event) throws Exception { 250 | TrainerMain trainer = new TrainerMain(); 251 | Stage stage = new Stage(); 252 | stage.initOwner(rootPane.getScene().getWindow()); 253 | stage.initModality(Modality.APPLICATION_MODAL); 254 | trainer.start(stage); 255 | stage.setOnCloseRequest((WindowEvent event1) -> { 256 | event1.consume(); 257 | stage.close(); 258 | }); 259 | } 260 | 261 | @FXML 262 | private void loadBatchImageTester(ActionEvent event) throws Exception { 263 | BatchImageTester tester = new BatchImageTester(); 264 | Stage stage = new Stage(); 265 | stage.initOwner(rootPane.getScene().getWindow()); 266 | stage.initModality(Modality.WINDOW_MODAL); 267 | tester.start(stage); 268 | } 269 | 270 | @FXML 271 | private void loadSingleImageTester(ActionEvent event) throws Exception { 272 | SingleImageCheck siCheck = new SingleImageCheck(); 273 | Stage stage = new Stage(); 274 | stage.initOwner(rootPane.getScene().getWindow()); 275 | stage.initModality(Modality.WINDOW_MODAL); 276 | siCheck.start(stage); 277 | stage.setOnCloseRequest((WindowEvent event1) -> { 278 | event1.consume(); 279 | stage.close(); 280 | }); 281 | } 282 | 283 | @FXML 284 | private void loadFullScreen(ActionEvent event) { 285 | Stage stage = (Stage) rootPane.getScene().getWindow(); 286 | stage.setFullScreen(true); 287 | } 288 | 289 | @FXML 290 | private void changeResultPropogation(ActionEvent event) { 291 | ConstantObjects.shouldPropogateResult = resultPropogation.isSelected(); 292 | } 293 | 294 | } 295 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/ui/controllers/MetadataDisplayController.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.ui.controllers; 2 | 3 | import com.jfoenix.controls.JFXButton; 4 | import com.jfoenix.controls.JFXTextArea; 5 | import com.gc.fakeimagedetection.core.metadata.MetadataProcessor; 6 | import java.net.URL; 7 | import java.util.ResourceBundle; 8 | import javafx.event.ActionEvent; 9 | import javafx.fxml.FXML; 10 | import javafx.fxml.Initializable; 11 | import javafx.stage.Stage; 12 | 13 | public class MetadataDisplayController implements Initializable { 14 | 15 | @FXML 16 | private JFXTextArea displayField; 17 | @FXML 18 | private JFXButton closeButton; 19 | 20 | @Override 21 | public void initialize(URL url, ResourceBundle rb) { 22 | displayField.setText(MetadataProcessor.extracted_data); 23 | } 24 | 25 | @FXML 26 | private void closeWindow(ActionEvent event) { 27 | Stage stage = (Stage) closeButton.getScene().getWindow(); 28 | stage.close(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/ui/controllers/MetadataResultController.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.ui.controllers; 2 | 3 | import com.jfoenix.controls.JFXButton; 4 | import com.jfoenix.controls.JFXSnackbar; 5 | import com.gc.fakeimagedetection.core.constants.ConstantObjects; 6 | import com.gc.fakeimagedetection.core.metadata.MetadataProcessor; 7 | import com.gc.fakeimagedetection.ui.alert.CommonUtil; 8 | import java.io.IOException; 9 | import java.net.URL; 10 | import java.util.ArrayList; 11 | import java.util.ResourceBundle; 12 | import java.util.logging.Level; 13 | import java.util.logging.Logger; 14 | import javafx.collections.FXCollections; 15 | import javafx.collections.ObservableList; 16 | import javafx.event.ActionEvent; 17 | import javafx.event.EventHandler; 18 | import javafx.fxml.FXML; 19 | import javafx.fxml.FXMLLoader; 20 | import javafx.fxml.Initializable; 21 | import javafx.scene.Node; 22 | import javafx.scene.Parent; 23 | import javafx.scene.Scene; 24 | import javafx.scene.chart.PieChart; 25 | import javafx.scene.control.Label; 26 | import javafx.scene.input.MouseEvent; 27 | import javafx.scene.layout.AnchorPane; 28 | import javafx.scene.paint.Color; 29 | import javafx.stage.Modality; 30 | import javafx.stage.Stage; 31 | import javafx.stage.StageStyle; 32 | 33 | public class MetadataResultController implements Initializable { 34 | 35 | @FXML 36 | private PieChart pie_chart; 37 | 38 | ObservableList pieChartData; 39 | @FXML 40 | private AnchorPane anchorPane; 41 | @FXML 42 | private JFXButton resultButton; 43 | 44 | MetadataDisplayController metadata_display_controller; 45 | int fakeness = 1; 46 | int real = 1; 47 | String output = ""; 48 | String fakeReason = ""; 49 | String realReason = ""; 50 | 51 | @Override 52 | public void initialize(URL url, ResourceBundle rb) { 53 | generatePercentage(); 54 | processResult(); 55 | 56 | } 57 | 58 | private void processResult() { 59 | String extractedData = MetadataProcessor.extracted_data; 60 | ArrayList components = new ArrayList<>(); 61 | for (String component : extractedData.split("\n")) { 62 | components.add(component); 63 | } 64 | 65 | if (extractedData.contains("Photoshop") || extractedData.contains("PHOTOSHOP")) { 66 | String version = ""; 67 | for (String component : components) { 68 | if (component.contains("Adobe Photoshop")) { 69 | try { 70 | version = component.substring(component.indexOf('A')); 71 | } catch (Exception e) { 72 | } 73 | } 74 | } 75 | if (version.length() < 2) { 76 | resultButton.setText("Fake Image With Adobe Tag\n"); 77 | } else { 78 | resultButton.setText("Tampered With\n" + version.replaceAll("[(,)]", "")); 79 | } 80 | resultButton.setStyle("-fx-background-color:#ff0000"); 81 | } else if (extractedData.contains("Gimp") || extractedData.contains("GIMP")) { 82 | resultButton.setText("Tampered With Gimp"); 83 | resultButton.setStyle("-fx-background-color:#ff0000"); 84 | } else if (real > fakeness) { 85 | if (fakeness < 3) { 86 | resultButton.setText("Seems like Real Camera Image"); 87 | resultButton.setStyle("-fx-background-color:#64DD17"); 88 | } else { 89 | resultButton.setText("Metadata Is Clean"); 90 | resultButton.setStyle("-fx-background-color:#64DD17"); 91 | } 92 | } else if (real == fakeness) { 93 | resultButton.setText("Cant Determine. Proceed with AI"); 94 | resultButton.setStyle("-fx-background-color:#455A64"); 95 | } else { 96 | resultButton.setText("Digitally Altered. Not from Camera"); 97 | resultButton.setStyle("-fx-background-color:#FF5722"); 98 | } 99 | 100 | if (extractedData.contains("Original Transmission Reference") && extractedData.contains("Special Instructions")) { 101 | JFXSnackbar snackbar = new JFXSnackbar(anchorPane); 102 | snackbar.getStylesheets().add(getClass().getResource("/resources/stylesheets/main.css").toExternalForm()); 103 | snackbar.show("Downloaded Image From Facebook", 10000); 104 | } 105 | if (extractedData.contains("Software - Google")) { 106 | JFXSnackbar snackbar = new JFXSnackbar(anchorPane); 107 | snackbar.getStylesheets().add(getClass().getResource("/resources/stylesheets/main.css").toExternalForm()); 108 | snackbar.show("Tampered By Google. May be from Google+", 10000); 109 | } 110 | 111 | } 112 | 113 | void displayMetaData() { 114 | try { 115 | FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/resources/fxml/metadatadisplay.fxml")); 116 | Parent root1 = (Parent) fxmlLoader.load(); 117 | metadata_display_controller = fxmlLoader.getController(); 118 | Stage stage = new Stage(); 119 | stage.initModality(Modality.WINDOW_MODAL); 120 | stage.resizableProperty().set(false); 121 | stage.setTitle("Metadata Information"); 122 | stage.setScene(new Scene(root1)); 123 | CommonUtil.attachIcon(stage); 124 | stage.show(); 125 | } catch (Exception e) { 126 | 127 | } 128 | } 129 | 130 | @FXML 131 | private void displayMoreInfo(ActionEvent event) { 132 | displayMetaData(); 133 | } 134 | 135 | private void generatePercentage() { 136 | real = 1; 137 | fakeness = 1; 138 | realReason = "Contains "; 139 | String extractedData = MetadataProcessor.extracted_data; 140 | ArrayList componentsToCheck = new ArrayList<>(); 141 | componentsToCheck.add("Exif IFD0"); 142 | componentsToCheck.add("Exif SubIFD"); 143 | componentsToCheck.add("Interoperability"); 144 | componentsToCheck.add("Exif Thumbnail"); 145 | componentsToCheck.add("Model"); 146 | componentsToCheck.add("Make"); 147 | componentsToCheck.add("Exposure Time "); 148 | componentsToCheck.add("F-Number"); 149 | componentsToCheck.add("Flash"); 150 | componentsToCheck.add("Focal Length"); 151 | for (String string : componentsToCheck) { 152 | if (extractedData.contains(string)) { 153 | real++; 154 | realReason += string + ","; 155 | if (real % 5 == 0) { 156 | realReason += "\n"; 157 | } 158 | } 159 | } 160 | realReason = realReason.substring(0, realReason.length() - 1); //Remove last Comma 161 | 162 | int ctr = 0; 163 | for (String string : MetadataProcessor.extracted_data.split("\n")) { 164 | ctr++; 165 | if (string.toUpperCase().contains("ADOBE")) { 166 | fakeness += 6; 167 | if (!fakeReason.contains("Detected Adobe Tag")) { 168 | fakeReason += "Detected Adobe Tag" + "\n"; 169 | } 170 | } 171 | if (string.toUpperCase().contains("PHOTOSHOP")) { 172 | fakeness += 15; 173 | if (!fakeReason.contains("Detected Photoshop Tag")) { 174 | fakeReason += "Detected Photoshop Tag" + "\n"; 175 | } 176 | } 177 | if (string.toUpperCase().contains("GIMP")) { 178 | fakeness += 15; 179 | if (!fakeReason.contains("Detected Gimp Tag")) { 180 | fakeReason += "Detected Gimp Tag" + "\n"; 181 | } 182 | } 183 | if (string.toUpperCase().contains("COREL")) { 184 | fakeness += 10; 185 | if (!fakeReason.contains("Detected Corel Tag")) { 186 | fakeReason += "Detected Corel Tag" + "\n"; 187 | } 188 | } 189 | if (string.toUpperCase().contains("PAINT")) { 190 | fakeness += 10; 191 | if (!fakeReason.contains("Detected Paint Tag")) { 192 | fakeReason += "Detected Paint Tag" + "\n"; 193 | } 194 | } 195 | if (string.toUpperCase().contains("PIXLR")) { 196 | fakeness += 10; 197 | if (!fakeReason.contains("Detected Pixlr Tag")) { 198 | fakeReason += "Detected Pixlr Tag" + "\n"; 199 | } 200 | } 201 | if (string.contains("Software - Google")) { 202 | fakeness += 10; 203 | if (!fakeReason.contains("Google's Signature Found: Possibly Google+")) { 204 | fakeReason += "Google's Signature Found: Possibly Google+" + "\n"; 205 | } 206 | } 207 | } 208 | 209 | if (ctr < 15) { 210 | fakeness += 4; 211 | fakeReason += "Very Low Metadata Content. Edited" + "\n"; 212 | } else if (ctr < 21) { 213 | fakeness += 3; 214 | fakeReason += "Low Metadata Content. Edited" + "\n"; 215 | } else if (ctr < 30) { 216 | fakeness += 1; 217 | fakeReason += "Average Metadata Content. Edited" + "\n"; 218 | } 219 | int total = fakeness + real; 220 | 221 | float fakenessPercentage = (float) fakeness / total; 222 | float realPercentage = (float) real / total; 223 | ConstantObjects.fakeness = fakenessPercentage; 224 | ConstantObjects.realness = realPercentage; 225 | System.out.println("Fakeness from metedata = " + fakenessPercentage); 226 | 227 | System.err.println("Number of metadata fields = " + ctr); 228 | ObservableList pieChartData 229 | = FXCollections.observableArrayList(); 230 | pie_chart.setData(pieChartData); 231 | pieChartData.add(new PieChart.Data("Fake", fakeness)); 232 | pieChartData.add(new PieChart.Data("Real", real)); 233 | pie_chart.setLegendVisible(false); 234 | pie_chart.setTitle(""); 235 | 236 | final Label caption = new Label(""); 237 | caption.setTextFill(Color.WHITE); 238 | caption.setStyle("-fx-font: 24 arial;"); 239 | final ObservableList children = anchorPane.getChildren(); 240 | children.add(caption); 241 | 242 | PieChart.Data data = pie_chart.getData().get(0); //Fake 243 | data.getNode().addEventHandler(MouseEvent.MOUSE_PRESSED, 244 | new EventHandler() { 245 | @Override 246 | public void handle(MouseEvent e) { 247 | caption.setTranslateX(e.getSceneX()); 248 | caption.setTranslateY(e.getSceneY()); 249 | String text = String.format("%.1f%%", 100 * data.getPieValue() / total); 250 | if (fakeReason.length() > 2) { 251 | JFXSnackbar snackbar = new JFXSnackbar(anchorPane); 252 | snackbar.getStylesheets().add(getClass().getResource("/resources/stylesheets/main.css").toExternalForm()); 253 | snackbar.show(fakeReason, 8000); 254 | } 255 | caption.setText(text); 256 | } 257 | }); 258 | 259 | PieChart.Data data1 = pie_chart.getData().get(1); //Fake 260 | data1.getNode().addEventHandler(MouseEvent.MOUSE_PRESSED, 261 | new EventHandler() { 262 | @Override 263 | public void handle(MouseEvent e) { 264 | caption.setTranslateX(e.getSceneX()); 265 | caption.setTranslateY(e.getSceneY()); 266 | String text = String.format("%.1f%%", 100 * data1.getPieValue() / total); 267 | if (realReason.length() > 10) { 268 | JFXSnackbar snackbar = new JFXSnackbar(anchorPane); 269 | snackbar.getStylesheets().add(getClass().getResource("/resources/stylesheets/main.css").toExternalForm()); 270 | snackbar.show(realReason + " Information", 8000); 271 | } 272 | caption.setText(text); 273 | } 274 | }); 275 | 276 | } 277 | 278 | } 279 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/ui/controllers/NetworkcreatorController.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.ui.controllers; 2 | 3 | import com.jfoenix.controls.JFXComboBox; 4 | import com.jfoenix.controls.JFXSpinner; 5 | import com.jfoenix.controls.JFXTextField; 6 | import com.gc.fakeimagedetection.core.listener.NeuralNetworkCreationCompleteListener; 7 | import com.gc.fakeimagedetection.core.neuralnet.MLPNetworkMaker; 8 | import com.gc.fakeimagedetection.ui.alert.Calert; 9 | import java.io.File; 10 | import java.net.URL; 11 | import java.util.ArrayList; 12 | import java.util.Arrays; 13 | import java.util.ResourceBundle; 14 | import javafx.collections.FXCollections; 15 | import javafx.collections.ObservableList; 16 | import javafx.event.ActionEvent; 17 | import javafx.fxml.FXML; 18 | import javafx.fxml.Initializable; 19 | import javafx.scene.control.Alert; 20 | import javafx.scene.layout.AnchorPane; 21 | import javafx.scene.layout.Pane; 22 | import javafx.stage.FileChooser; 23 | import org.neuroph.core.NeuralNetwork; 24 | import org.neuroph.imgrec.ColorMode; 25 | import org.neuroph.imgrec.image.Dimension; 26 | import org.neuroph.util.TransferFunctionType; 27 | 28 | public class NetworkcreatorController implements Initializable, NeuralNetworkCreationCompleteListener { 29 | 30 | @FXML 31 | private JFXTextField neuralNetLabel; 32 | @FXML 33 | private JFXTextField width; 34 | @FXML 35 | private JFXTextField height; 36 | @FXML 37 | private JFXComboBox colorMode; 38 | @FXML 39 | private JFXTextField neuronLabelList; 40 | @FXML 41 | private JFXTextField neuronCountList; 42 | @FXML 43 | private JFXComboBox transferFunction; 44 | @FXML 45 | private Pane container; 46 | @FXML 47 | private AnchorPane rootPane; 48 | @FXML 49 | private JFXSpinner loadingSpinner; 50 | 51 | @Override 52 | public void initialize(URL url, ResourceBundle rb) { 53 | loadingSpinner.setVisible(false); 54 | 55 | //Add ColorModes , 56 | ObservableList list = FXCollections.observableArrayList(); 57 | list.add("COLOR_RGB"); 58 | list.add("COLOR_HSL"); 59 | list.add("BLACK_AND_WHITE"); 60 | colorMode.getItems().setAll(list); 61 | 62 | //Add TransferFunctionss 63 | ObservableList listTransferFunctions = FXCollections.observableArrayList(); 64 | listTransferFunctions.add("LINEAR"); 65 | listTransferFunctions.add("RAMP"); 66 | listTransferFunctions.add("STEP"); 67 | listTransferFunctions.add("SIGMOID"); 68 | listTransferFunctions.add("TANH"); 69 | listTransferFunctions.add("GAUSSIAN"); 70 | listTransferFunctions.add("TRAPEZOID"); 71 | listTransferFunctions.add("SGN"); 72 | listTransferFunctions.add("SIN"); 73 | listTransferFunctions.add("LOG"); 74 | transferFunction.getItems().setAll(listTransferFunctions); 75 | 76 | } 77 | 78 | @FXML 79 | private void saveNeuralNet(ActionEvent event) { 80 | String neuralNetLbl = neuralNetLabel.getText(); 81 | Dimension samplingDimension = new Dimension(Integer.parseInt(width.getText()), 82 | Integer.parseInt(height.getText())); 83 | ColorMode mode; 84 | switch (colorMode.getSelectionModel().getSelectedItem()) { 85 | case "COLOR_RGB": 86 | mode = ColorMode.COLOR_RGB; 87 | break; 88 | case "COLOR_HSL": 89 | mode = ColorMode.COLOR_HSL; 90 | break; 91 | case "BLACK_AND_WHITE": 92 | mode = ColorMode.COLOR_RGB; 93 | break; 94 | default: 95 | mode = ColorMode.COLOR_RGB; 96 | break; 97 | } 98 | TransferFunctionType tFunction; 99 | switch (transferFunction.getSelectionModel().getSelectedItem()) { 100 | case "LINEAR": 101 | tFunction = TransferFunctionType.LINEAR; 102 | break; 103 | case "RAMP": 104 | tFunction = TransferFunctionType.RAMP; 105 | break; 106 | case "STEP": 107 | tFunction = TransferFunctionType.STEP; 108 | break; 109 | case "SIGMOID": 110 | tFunction = TransferFunctionType.SIGMOID; 111 | break; 112 | case "TANH": 113 | tFunction = TransferFunctionType.TANH; 114 | break; 115 | case "GAUSSIAN": 116 | tFunction = TransferFunctionType.GAUSSIAN; 117 | break; 118 | case "TRAPEZOID": 119 | tFunction = TransferFunctionType.TRAPEZOID; 120 | break; 121 | case "SGN": 122 | tFunction = TransferFunctionType.SGN; 123 | break; 124 | case "SIN": 125 | tFunction = TransferFunctionType.SIN; 126 | break; 127 | case "LOG": 128 | tFunction = TransferFunctionType.LOG; 129 | break; 130 | default: 131 | tFunction = TransferFunctionType.GAUSSIAN; 132 | break; 133 | } 134 | 135 | ArrayList neuronLabels = new ArrayList(Arrays.asList(neuronLabelList.getText().split("[,]"))); 136 | ArrayList neuronCounts = new ArrayList(); 137 | 138 | for (String neuronCount : neuronCountList.getText().split("[,]")) { 139 | neuronCounts.add(Integer.parseInt(neuronCount.replaceAll(" ", ""))); 140 | System.out.println("neuronCounts = " + neuronCount); 141 | } 142 | 143 | //Show File save dialog 144 | FileChooser fileChooser = new FileChooser(); 145 | fileChooser.setTitle("Save Neural Network"); 146 | File file = fileChooser.showSaveDialog(rootPane.getScene().getWindow()); 147 | if (file == null) { 148 | Calert.showAlert("Not a valid File", "Select target again", Alert.AlertType.ERROR); 149 | return; 150 | } 151 | MLPNetworkMaker maker = new MLPNetworkMaker(neuralNetLbl, samplingDimension, mode, neuronLabels, neuronCounts, tFunction, file.getAbsolutePath()); 152 | maker.setListener(this); 153 | Thread nnetCreator = new Thread(maker); 154 | nnetCreator.start(); 155 | loadingSpinner.setVisible(true); 156 | } 157 | 158 | @Override 159 | public void networkCreationComplete(Boolean flag) { 160 | loadingSpinner.setVisible(false); 161 | if (flag) { 162 | Calert.showAlert("Done", "Neural Network Saved Successfully", Alert.AlertType.INFORMATION); 163 | } 164 | } 165 | 166 | } 167 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/ui/controllers/NeuralnetInterfaceController.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.ui.controllers; 2 | 3 | import com.jfoenix.controls.JFXButton; 4 | import com.jfoenix.controls.JFXSnackbar; 5 | import com.gc.fakeimagedetection.core.constants.ConstantObjects; 6 | import com.gc.fakeimagedetection.core.errorlevelanalysis.FIDErrorLevelAnalysis; 7 | import com.gc.fakeimagedetection.core.listener.ErrorLevelAnalysisListener; 8 | import com.gc.fakeimagedetection.core.listener.NeuralnetProcessorListener; 9 | import com.gc.fakeimagedetection.core.metadata.MetadataProcessor; 10 | import com.gc.fakeimagedetection.core.processor.NeuralNetProcessor; 11 | import com.gc.fakeimagedetection.core.trainer.SingleImageTrainer; 12 | import com.gc.fakeimagedetection.core.listener.ThreadCompleteListener; 13 | import com.gc.fakeimagedetection.ui.alert.Calert; 14 | import ij.ImagePlus; 15 | import java.awt.Dimension; 16 | import java.awt.image.BufferedImage; 17 | import java.io.IOException; 18 | import java.net.URL; 19 | import java.text.DecimalFormat; 20 | import java.util.HashMap; 21 | import java.util.Optional; 22 | import java.util.ResourceBundle; 23 | import java.util.logging.Level; 24 | import java.util.logging.Logger; 25 | import javafx.animation.KeyFrame; 26 | import javafx.animation.KeyValue; 27 | import javafx.animation.ParallelTransition; 28 | import javafx.animation.ScaleTransition; 29 | import javafx.animation.Timeline; 30 | import javafx.animation.TranslateTransition; 31 | import javafx.application.Platform; 32 | import javafx.event.Event; 33 | import javafx.event.EventHandler; 34 | import javafx.fxml.FXML; 35 | import javafx.fxml.FXMLLoader; 36 | import javafx.fxml.Initializable; 37 | import javafx.scene.Scene; 38 | import javafx.scene.control.Alert; 39 | import javafx.scene.control.Alert.AlertType; 40 | import javafx.scene.control.ButtonBar.ButtonData; 41 | import javafx.scene.control.ButtonType; 42 | import javafx.scene.image.ImageView; 43 | import javafx.scene.input.MouseButton; 44 | import javafx.scene.input.MouseEvent; 45 | import javafx.scene.layout.AnchorPane; 46 | import javafx.scene.layout.StackPane; 47 | import javafx.scene.text.Text; 48 | import javafx.stage.Stage; 49 | import javafx.util.Duration; 50 | import javax.imageio.ImageIO; 51 | 52 | public class NeuralnetInterfaceController implements 53 | Initializable, ErrorLevelAnalysisListener, ThreadCompleteListener, NeuralnetProcessorListener { 54 | 55 | public static String imageLocation = ""; 56 | 57 | public static String getImageLocation() { 58 | return imageLocation = LaunchScreeenController.processingFile.getAbsolutePath(); 59 | } 60 | 61 | @FXML 62 | private StackPane rootPane; 63 | @FXML 64 | private ImageView backgroundImageView; 65 | @FXML 66 | private AnchorPane anchorPane; 67 | @FXML 68 | private Text description; 69 | @FXML 70 | private Text christopher; 71 | @FXML 72 | private JFXButton navigation_button; 73 | @FXML 74 | private ImageView homeIcon; 75 | 76 | NeuralnetInterfaceController thisObject = this; 77 | ScaleTransition bulgingTransition; 78 | FIDErrorLevelAnalysis elaAnalyzer; 79 | NeuralNetProcessor nprocessor; 80 | BufferedImage elaImage; 81 | 82 | @Override 83 | public void initialize(URL url, ResourceBundle rb) { 84 | startAnimation(); 85 | getImageLocation(); 86 | 87 | elaAnalyzer = new FIDErrorLevelAnalysis(imageLocation, 95, new Dimension(100, 100), this); 88 | elaAnalyzer.setName("elaAnalyzer"); 89 | elaAnalyzer.start(); 90 | 91 | } 92 | 93 | private void startAnimation() { 94 | navigation_button.setText("Applying ELA on Image"); 95 | float animationExtension = 1.2f; 96 | bulgingTransition = new ScaleTransition(Duration.millis(2000), navigation_button); 97 | bulgingTransition.setToX(animationExtension); 98 | bulgingTransition.setToY(animationExtension); 99 | bulgingTransition.autoReverseProperty().setValue(true); 100 | bulgingTransition.setCycleCount(bulgingTransition.INDEFINITE); 101 | bulgingTransition.play(); 102 | } 103 | 104 | @FXML 105 | private void loadAnimation(MouseEvent event) { 106 | } 107 | 108 | @FXML 109 | private void rollBack(MouseEvent event) { 110 | LaunchScreeenController.processingFile = null; 111 | MetadataProcessor.extracted_data = ""; 112 | try { 113 | Stage stage = (Stage) rootPane.getScene().getWindow(); 114 | Scene pane = new Scene(FXMLLoader.load(getClass().getResource("/resources/fxml/launch.fxml"))); 115 | stage.setScene(pane); 116 | } catch (IOException ex) { 117 | Logger.getLogger(NeuralnetInterfaceController.class.getName()).log(Level.SEVERE, null, ex); 118 | } 119 | } 120 | 121 | void updateIndicatorText(String message) { 122 | Platform.runLater(new Runnable() { 123 | @Override 124 | public void run() { 125 | navigation_button.setText(message); 126 | } 127 | }); 128 | } 129 | 130 | void finalMoveOfIndicator() { 131 | Platform.runLater(new Runnable() { 132 | @Override 133 | public void run() { 134 | Timeline timeline = new Timeline(); 135 | timeline.setCycleCount(1); 136 | 137 | KeyValue keyValueX = new KeyValue(navigation_button.prefWidthProperty(), 300); 138 | KeyFrame keyFrame = new KeyFrame(Duration.millis(2000), keyValueX); 139 | timeline.getKeyFrames().add(keyFrame); 140 | 141 | timeline.play(); 142 | navigation_button.setStyle("-fx-background-radius: 0px;"); 143 | } 144 | }); 145 | } 146 | 147 | void loadResult(HashMap result) { 148 | System.out.println("Metadata Result: Fakeness = " + ConstantObjects.fakeness); 149 | if (ConstantObjects.fakeness < 0) { 150 | System.out.println("Invalid Result from metadata"); 151 | } 152 | 153 | Platform.runLater(new Runnable() { 154 | final float NEURAL_NET_WEIGHT = 0.4f; 155 | final float METADATA_NET_WEIGHT = 1-NEURAL_NET_WEIGHT; 156 | 157 | @Override 158 | public void run() { 159 | double real = result.get("real") * 100; 160 | double fake = result.get("faked") * 100; 161 | 162 | DecimalFormat df2 = new DecimalFormat(".#"); 163 | if (ConstantObjects.shouldPropogateResult) { 164 | real = (real*NEURAL_NET_WEIGHT) + (METADATA_NET_WEIGHT * ConstantObjects.realness*100); 165 | fake = (fake*NEURAL_NET_WEIGHT) + (METADATA_NET_WEIGHT * ConstantObjects.fakeness*100); 166 | } 167 | 168 | if (real < 10 && fake < 10) { 169 | String possibility; 170 | if (real >= fake) { 171 | possibility = "Possibly Real"; 172 | } else { 173 | possibility = "Possibly Fake"; 174 | } 175 | navigation_button.setStyle("-fx-background-color:#EF6C00"); 176 | navigation_button.setText("Cant Determine whether fake or not " + possibility); 177 | 178 | } else if (fake > real) { 179 | navigation_button.setStyle("-fx-background-color:#f44336"); 180 | navigation_button.setText("FAKE IMAGE" + "\nConfidence :" + df2.format(fake) + "%"); 181 | } else if (fake < real) { 182 | navigation_button.setStyle("-fx-background-color:#4CAF50"); 183 | navigation_button.setText("REAL IMAGE" + "\nConfidence :" + df2.format(real) + "%"); 184 | } else { 185 | navigation_button.setStyle("-fx-background-color:#4CAF50"); 186 | navigation_button.setText("Process Failed. 50-50 Chance"); 187 | } 188 | 189 | final JFXSnackbar snackbar = new JFXSnackbar(rootPane); 190 | snackbar.getStylesheets().add(getClass().getResource("/resources/stylesheets/main.css").toExternalForm()); 191 | EventHandler handler = new EventHandler() { 192 | @Override 193 | public void handle(Event event) { 194 | snackbar.unregisterSnackbarContainer(rootPane); 195 | Alert alert = new Alert(AlertType.CONFIRMATION); 196 | alert.setTitle("Confirmation Dialog"); 197 | alert.setContentText("Is this image Fake or Real ?"); 198 | 199 | ButtonType fakeButton = new ButtonType("Fake"); 200 | ButtonType realButton = new ButtonType("Real"); 201 | ButtonType buttonTypeCancel = new ButtonType("Cancel", ButtonData.CANCEL_CLOSE); 202 | 203 | alert.getButtonTypes().setAll(fakeButton, realButton, buttonTypeCancel); 204 | 205 | Optional result = alert.showAndWait(); 206 | if (result.get() == fakeButton) { 207 | navigation_button.setText("Learning..."); 208 | SingleImageTrainer learner 209 | = new SingleImageTrainer(NeuralNetProcessor.nnet, elaImage, false); 210 | learner.addListener(thisObject); 211 | learner.setName("learner"); 212 | learner.start(); 213 | } else if (result.get() == realButton) { 214 | navigation_button.setText("Learning..."); 215 | SingleImageTrainer learner 216 | = new SingleImageTrainer(NeuralNetProcessor.nnet, elaImage, true); 217 | learner.addListener(thisObject); 218 | learner.setName("learner"); 219 | learner.start(); 220 | } else { 221 | 222 | } 223 | } 224 | }; 225 | snackbar.show("Isn't That Right ? Help Me Grow", "Okay", 10000, handler); 226 | 227 | addELAListener(); 228 | } 229 | 230 | private void addELAListener() { 231 | navigation_button.setOnAction((e) -> { 232 | }); 233 | 234 | navigation_button.setOnMousePressed(new EventHandler() { 235 | @Override 236 | public void handle(MouseEvent event) { 237 | if (event.getButton() == MouseButton.PRIMARY) { 238 | new ImagePlus("Error Level Analysis", elaImage).show(); 239 | } else if (event.getButton() == MouseButton.SECONDARY) { 240 | try { 241 | new ImagePlus("Original Image", ImageIO.read(LaunchScreeenController.processingFile)).show(); 242 | } catch (IOException ex) { 243 | Logger.getLogger(NeuralnetInterfaceController.class.getName()).log(Level.SEVERE, null, ex); 244 | } 245 | } 246 | } 247 | }); 248 | } 249 | }); 250 | } 251 | 252 | private void removeBannersandDescs() { 253 | TranslateTransition tChristopher = new TranslateTransition(Duration.millis(1000), christopher); 254 | TranslateTransition tDescription = new TranslateTransition(Duration.millis(1000), description); 255 | tChristopher.setToY(-500); 256 | tDescription.setToY(-500); 257 | ParallelTransition pt = new ParallelTransition(tChristopher, tDescription); 258 | pt.play(); 259 | 260 | } 261 | 262 | @Override 263 | public void notifyOfThreadComplete(Thread thread) { 264 | switch (thread.getName()) { 265 | case "learner": 266 | updateIndicatorText("Learning Complete"); 267 | break; 268 | } 269 | } 270 | 271 | @Override 272 | public void elaCompleted(BufferedImage image) { 273 | updateIndicatorText("Serializing Image"); 274 | elaImage = image; 275 | updateIndicatorText("Connecting to Neural Network"); 276 | nprocessor = new NeuralNetProcessor(elaImage); 277 | nprocessor.setName("nprocessor"); 278 | nprocessor.addListener(this); 279 | nprocessor.setListener(this); 280 | nprocessor.start(); 281 | removeBannersandDescs(); 282 | } 283 | 284 | @Override 285 | public void neuralnetProcessCompleted(HashMap result) { 286 | if (result == null) { 287 | Platform.runLater(new Runnable() { 288 | @Override 289 | public void run() { 290 | Calert.showAlert("Forced Rollback", "Image Detection Failed:\nCorrupted File", AlertType.ERROR); 291 | rollBack(null); 292 | return; 293 | } 294 | }); 295 | } 296 | bulgingTransition.stop(); 297 | updateIndicatorText("Done"); 298 | System.out.println("Neural net result:-\n" + result); 299 | loadResult(result); 300 | } 301 | } 302 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/ui/controllers/SingleImageAnalyzerController.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.ui.controllers; 2 | 3 | import com.jfoenix.controls.JFXButton; 4 | import com.jfoenix.controls.JFXCheckBox; 5 | import com.gc.fakeimagedetection.ui.alert.Calert; 6 | import static com.gc.fakeimagedetection.core.processor.NeuralNetProcessor.nnet; 7 | import java.io.File; 8 | import java.io.FileInputStream; 9 | import java.io.FileNotFoundException; 10 | import java.io.IOException; 11 | import java.net.URL; 12 | import java.util.HashMap; 13 | import java.util.ResourceBundle; 14 | import java.util.logging.Level; 15 | import java.util.logging.Logger; 16 | import javafx.event.ActionEvent; 17 | import javafx.fxml.FXML; 18 | import javafx.fxml.Initializable; 19 | import javafx.scene.control.Alert; 20 | import javafx.scene.layout.AnchorPane; 21 | import javafx.stage.FileChooser; 22 | import javax.imageio.ImageIO; 23 | import org.neuroph.core.NeuralNetwork; 24 | import org.neuroph.imgrec.ImageRecognitionPlugin; 25 | 26 | public class SingleImageAnalyzerController implements Initializable { 27 | 28 | @FXML 29 | private JFXButton neuralSource; 30 | @FXML 31 | private JFXCheckBox nnIndicator; 32 | @FXML 33 | private JFXButton imgSource; 34 | @FXML 35 | private JFXCheckBox imgIndicator; 36 | @FXML 37 | private JFXButton startButton; 38 | 39 | File nnetSrc; 40 | File imgSrc; 41 | @FXML 42 | private AnchorPane rootPane; 43 | 44 | @Override 45 | public void initialize(URL url, ResourceBundle rb) { 46 | // TODO 47 | } 48 | 49 | @FXML 50 | private void loadNeuralNetwork(ActionEvent event) { 51 | FileChooser fileChooser = new FileChooser(); 52 | fileChooser.setTitle("Select Neural Network"); 53 | nnetSrc = fileChooser.showOpenDialog(rootPane.getScene().getWindow()); 54 | if (nnetSrc != null) { 55 | nnIndicator.setSelected(true); 56 | } 57 | } 58 | 59 | @FXML 60 | private void loadImage(ActionEvent event) { 61 | FileChooser fileChooser = new FileChooser(); 62 | fileChooser.setTitle("Select Image"); 63 | imgSrc = fileChooser.showOpenDialog(rootPane.getScene().getWindow()); 64 | if (imgSrc != null) { 65 | imgIndicator.setSelected(true); 66 | } 67 | } 68 | 69 | @FXML 70 | private void startCheck(ActionEvent event) throws IOException { 71 | if (nnetSrc == null || imgSrc == null) { 72 | Calert.showAlert("Invalid Data", "Select Required Files", Alert.AlertType.ERROR); 73 | return; 74 | } 75 | try { 76 | nnet = NeuralNetwork.load(new FileInputStream(nnetSrc)); // load trained neural network saved with Neuroph Studio 77 | System.out.println("Learning Rule = " + nnet.getLearningRule()); 78 | ImageRecognitionPlugin imageRecognition = (ImageRecognitionPlugin) nnet.getPlugin(ImageRecognitionPlugin.class); // get the 79 | HashMap output = imageRecognition.recognizeImage(ImageIO.read(imgSrc)); 80 | if (output == null) { 81 | System.err.println("Image Recognition Failed"); 82 | } 83 | double real = output.get("real"); 84 | double fake = output.get("faked"); 85 | System.out.println(output.toString()); 86 | Calert.showAlert("Result", "Real = " + real + "\nFake = " + fake, Alert.AlertType.INFORMATION); 87 | } catch (FileNotFoundException ex) { 88 | Logger.getLogger(SingleImageAnalyzerController.class.getName()).log(Level.SEVERE, null, ex); 89 | } 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /src/com/gc/fakeimagedetection/ui/controllers/TrainingInterfaceController.java: -------------------------------------------------------------------------------- 1 | package com.gc.fakeimagedetection.ui.controllers; 2 | 3 | import com.jfoenix.controls.JFXButton; 4 | import com.jfoenix.controls.JFXCheckBox; 5 | import com.jfoenix.controls.JFXSpinner; 6 | import com.jfoenix.controls.JFXTextField; 7 | import com.gc.fakeimagedetection.core.listener.BatchImageTrainingListener; 8 | import com.gc.fakeimagedetection.ui.alert.Calert; 9 | import com.gc.fakeimagedetection.core.trainer.BatchImageTrainer; 10 | import java.awt.Dimension; 11 | import java.io.File; 12 | import java.net.URL; 13 | import java.util.ArrayList; 14 | import java.util.ResourceBundle; 15 | import javafx.application.Platform; 16 | import javafx.beans.value.ChangeListener; 17 | import javafx.beans.value.ObservableValue; 18 | import javafx.event.ActionEvent; 19 | import javafx.fxml.FXML; 20 | import javafx.fxml.FXMLLoader; 21 | import javafx.fxml.Initializable; 22 | import javafx.scene.Parent; 23 | import javafx.scene.Scene; 24 | import javafx.scene.chart.CategoryAxis; 25 | import javafx.scene.chart.LineChart; 26 | import javafx.scene.chart.NumberAxis; 27 | import javafx.scene.chart.XYChart; 28 | import javafx.scene.control.Alert; 29 | import javafx.scene.control.CheckBox; 30 | import javafx.scene.layout.AnchorPane; 31 | import javafx.scene.layout.Pane; 32 | import javafx.stage.DirectoryChooser; 33 | import javafx.stage.FileChooser; 34 | import javafx.stage.Modality; 35 | import javafx.stage.Stage; 36 | 37 | public class TrainingInterfaceController implements 38 | Initializable, BatchImageTrainingListener { 39 | 40 | @FXML 41 | private JFXButton sourceIndicator; 42 | @FXML 43 | private CheckBox srcIndicator; 44 | @FXML 45 | private JFXTextField realLabel; 46 | @FXML 47 | private JFXTextField fakeLabel; 48 | @FXML 49 | private JFXButton startButton; 50 | @FXML 51 | private AnchorPane rootPane; 52 | @FXML 53 | private JFXTextField width; 54 | @FXML 55 | private JFXTextField height; 56 | @FXML 57 | private JFXTextField learningRate; 58 | @FXML 59 | private JFXTextField momentum; 60 | @FXML 61 | private JFXTextField maxError; 62 | @FXML 63 | private LineChart errorChart; 64 | @FXML 65 | private NumberAxis yAxis; 66 | @FXML 67 | private CategoryAxis xAxis; 68 | @FXML 69 | private JFXButton saveButton; 70 | @FXML 71 | private JFXButton neuralSource; 72 | @FXML 73 | private JFXCheckBox nnIndicator; 74 | @FXML 75 | private Pane containerPlane; 76 | @FXML 77 | private JFXSpinner spinner; 78 | 79 | 80 | ArrayList imageLabels; 81 | File srcDir = null; 82 | File nnFile = null; 83 | String rLabel = ""; 84 | String fLabel = ""; 85 | XYChart.Series series; 86 | BatchImageTrainer neuralTrainer; 87 | 88 | @Override 89 | public void initialize(URL url, ResourceBundle rb) { 90 | imageLabels = new ArrayList<>(); 91 | series = new XYChart.Series(); 92 | series.setName("Learning Curve 1"); 93 | errorChart.getData().add(series); 94 | 95 | spinner.setVisible(false); 96 | } 97 | 98 | 99 | @FXML 100 | private void loadImageSource(ActionEvent event) { 101 | DirectoryChooser chooser = new DirectoryChooser(); 102 | chooser.setTitle("Choose Traing Set"); 103 | srcDir = chooser.showDialog(rootPane.getScene().getWindow()); 104 | if (srcDir == null) { 105 | Calert.showAlert("Error", "Not a valid folder", Alert.AlertType.ERROR); 106 | return; 107 | } 108 | 109 | System.out.println("Loading Dataset from " + srcDir.getAbsolutePath()); 110 | srcIndicator.setSelected(true); 111 | } 112 | 113 | @FXML 114 | private void startTraining(ActionEvent event) { 115 | switch (startButton.getAccessibleText()) { 116 | case "start": 117 | try { 118 | rLabel = realLabel.getText(); 119 | fLabel = fakeLabel.getText(); 120 | imageLabels.add(fLabel); 121 | imageLabels.add(rLabel); 122 | int sampledWidth = Integer.parseInt(width.getText()); 123 | int sampledheight = Integer.parseInt(height.getText()); 124 | float lRate = Float.parseFloat(learningRate.getText()); 125 | float moment = Float.parseFloat(momentum.getText()); 126 | float mError = Float.parseFloat(maxError.getText()); 127 | if (srcDir == null || nnFile == null) { 128 | Calert.showAlert("Incomplete Configuration Data", "Check parameters", Alert.AlertType.ERROR); 129 | return; 130 | } 131 | 132 | System.out.println("Starting training procedure"); 133 | neuralTrainer = new BatchImageTrainer(srcDir, nnFile, 134 | new Dimension(sampledWidth, sampledWidth), imageLabels, this); 135 | neuralTrainer.setMaxError(mError); 136 | neuralTrainer.setMomentum(moment); 137 | neuralTrainer.setLearningRate(lRate); 138 | neuralTrainer.start(); 139 | spinner.setVisible(true); 140 | 141 | startButton.setAccessibleText("stop"); 142 | startButton.setStyle("-fx-background-color:#e53935;-fx-text-fill:#ffffff"); 143 | startButton.setText("Stop Training"); 144 | } catch (Exception e) { 145 | Calert.showAlert("Incomplete Configuration Data", e.getMessage(), Alert.AlertType.ERROR); 146 | } 147 | break; 148 | case "stop": 149 | neuralTrainer.stopLearning(); 150 | startButton.setAccessibleText("stopped"); 151 | startButton.setText("Stopped"); 152 | break; 153 | default: 154 | System.out.println("Invalid Accessible Text"); 155 | 156 | } 157 | 158 | } 159 | 160 | @FXML 161 | private void saveLearnedNetwork(ActionEvent event) { 162 | FileChooser fileChooser = new FileChooser(); 163 | fileChooser.setTitle("Save Neural Network"); 164 | File file = fileChooser.showSaveDialog(rootPane.getScene().getWindow()); 165 | neuralTrainer.saveLearnedNetwork(file.getAbsolutePath()); 166 | } 167 | 168 | @FXML 169 | private void loadNeuralNetwork(ActionEvent event) { 170 | FileChooser fileChooser = new FileChooser(); 171 | fileChooser.setTitle("Open Resource File"); 172 | 173 | fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter("Neural Nets", "*.nnet")); 174 | nnFile = fileChooser.showOpenDialog(rootPane.getScene().getWindow()); 175 | 176 | if (nnFile == null) { 177 | Calert.showAlert("Error", "Not a valid neural network", Alert.AlertType.ERROR); 178 | return; 179 | } 180 | 181 | System.out.println("Training Neural " + nnFile.getAbsolutePath()); 182 | nnIndicator.setSelected(true); 183 | } 184 | 185 | @FXML 186 | private void loadNewTrainingWindow(ActionEvent event) { 187 | try { 188 | FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/resources/fxml/traininginterface.fxml")); 189 | Parent root1 = (Parent) fxmlLoader.load(); 190 | Stage stage = new Stage(); 191 | stage.initModality(Modality.APPLICATION_MODAL); 192 | stage.setTitle("Neural Network Trainer"); 193 | stage.setScene(new Scene(root1)); 194 | stage.show(); 195 | } catch (Exception e) { 196 | Calert.showAlert("Cant launch new window", e.getMessage(), Alert.AlertType.ERROR); 197 | } 198 | } 199 | 200 | @Override 201 | public void batchImageTrainingCompleted() { 202 | saveButton.setDisable(false); 203 | spinner.setVisible(false); 204 | } 205 | 206 | @Override 207 | public void batchImageTrainingUpdate(int iteration, Double error) { 208 | Platform.runLater(new Runnable() { 209 | @Override 210 | public void run() { 211 | series.getData().add(new XYChart.Data(String.valueOf(iteration), error)); 212 | } 213 | }); 214 | } 215 | 216 | } 217 | -------------------------------------------------------------------------------- /src/resources/fxml/batchimageprocessor.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/resources/fxml/batchimagetester.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/resources/fxml/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afsalashyana/FakeImageDetection/7466fa9f3b01a5e34987651a51aab9172a118bf6/src/resources/fxml/home.png -------------------------------------------------------------------------------- /src/resources/fxml/infinity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afsalashyana/FakeImageDetection/7466fa9f3b01a5e34987651a51aab9172a118bf6/src/resources/fxml/infinity.png -------------------------------------------------------------------------------- /src/resources/fxml/launch.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 |
103 |
104 | -------------------------------------------------------------------------------- /src/resources/fxml/metadatadisplay.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/resources/fxml/metadataresult.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/resources/fxml/networkcreator.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/resources/fxml/neuralinterface.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /src/resources/fxml/singleimage.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/resources/fxml/traininginterface.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /src/resources/icon/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afsalashyana/FakeImageDetection/7466fa9f3b01a5e34987651a51aab9172a118bf6/src/resources/icon/icon.png -------------------------------------------------------------------------------- /src/resources/icon/icon_high.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afsalashyana/FakeImageDetection/7466fa9f3b01a5e34987651a51aab9172a118bf6/src/resources/icon/icon_high.png -------------------------------------------------------------------------------- /src/resources/stylesheets/main.css: -------------------------------------------------------------------------------- 1 | .panel2{ 2 | -fx-background-color: #0f0f0f; 3 | } 4 | 5 | /*welcome screen main navigation button*/ 6 | .load_image_button{ 7 | -fx-background-color: #03A9F4; 8 | -fx-background-radius: 200px; 9 | -fx-text-fill: #ffffff; 10 | } 11 | 12 | .meta_data_result{ 13 | -fx-background-color: #03A9F4; 14 | -fx-text-fill: #ffffff; 15 | } 16 | 17 | .launch_panel{ 18 | -fx-background-color: black; 19 | } 20 | 21 | /*Overriding default Pie chart colours*/ 22 | .default-color0.chart-pie { -fx-pie-color: #f44336; } 23 | .default-color1.chart-pie { -fx-pie-color: #76FF03; } 24 | 25 | /*Piechart title style*/ 26 | .chart-title { 27 | -fx-text-fill: #ffffff; 28 | -fx-font-size: 1.6em; 29 | } 30 | /*Piechart content styles*/ 31 | .chart-content { 32 | -fx-padding: 30px; 33 | -fx-text-fill: #ffffff; 34 | } 35 | /*Piechart axis label*/ 36 | .axis-label { 37 | -fx-text-fill: #ffffff; 38 | } 39 | 40 | .chart-pie-label-line { 41 | -fx-stroke: #ffffff; 42 | -fx-fill: #ffffff; 43 | } 44 | 45 | .chart-pie-label { 46 | -fx-fill: #ffffff; 47 | -fx-font-size: 1.5em; 48 | } 49 | 50 | /*Metadata result snackbar styling*/ 51 | 52 | .jfx-snackbar-content { 53 | -fx-background-color: #FFFFFF; 54 | } 55 | .jfx-snackbar-toast { 56 | -fx-text-fill: #000000; 57 | -fx-font-size: 16; 58 | } 59 | --------------------------------------------------------------------------------