├── .gitignore ├── LICENSE ├── README.md ├── code ├── __init__.py ├── config.py ├── dataset │ └── Dresden.txt ├── network.py ├── test.py ├── train.py └── utils │ ├── __init__.py │ ├── download.py │ ├── generator.py │ ├── splicing.py │ └── tools.py ├── experiment ├── 1_1.ipynb ├── 2-1.ipynb └── 2-2.ipynb ├── main.py ├── paper_RFM.pdf └── static ├── result-2.jpg └── result-3.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.pyc 3 | *logs 4 | -------------------------------------------------------------------------------- /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 | # Reliability Fusing Map (RFM) 2 | 3 | This repository is implementation of "Image Tampering Detection and Localization via Reliability Fusion Map” (RFM). The main contributions are summarized as follows (1) obtaining higher accuracy; (2) reducing computational complexity of clustering; (3) improving localization fineness from 64 x 64 to 32 x 32. 4 | 5 |
6 | 7 | 8 | # Citation 9 | ``` 10 | @article{yao2020image, 11 | title={Image Forgery Detection and Localization via a Reliability Fusion Map}, 12 | author={Yao, Hongwei and Xu, Ming and Qiao, Tong and Wu, Yiming and Zheng, Ning}, 13 | journal={Sensors}, 14 | volume={20}, 15 | number={22}, 16 | pages={6668}, 17 | year={2020}, 18 | publisher={Multidisciplinary Digital Publishing Institute} 19 | } 20 | ``` 21 | 22 |
23 | 24 | # Prerequisites 25 | 26 | * tensorflow == 1.7.0 27 | * pandas == 0.23.4 28 | * scipy == 1.1.0 29 | * sklearn == 0.19.2 30 | * matplotlib == 2.2.3 31 | * Pillow == 5.2.0 32 | 33 |
34 | 35 | 36 | # Usage 37 | 38 | * Run pretrain model: 39 | 40 | 1. You can download pretrain model at: [Baidu disk](https://pan.baidu.com/s/1mYEHwtQdIUb5vugruUppRA), password=`mxqr` 41 | [Google drive](https://drive.google.com/file/d/1ULTmA1Ef5Y8NcOc1bSF8Ksj7rapaN0zO/view?usp=sharing) 42 | 43 | put unzip folder into `code/model/{scope_name}`, see `{scope_name}` in `code.config.py` 44 | 45 | 2. Run pre-train test using command: 46 | 47 | > python main.py --code.config --action test 48 | 49 | where `code.config.py` is config file including CNN architecture, dataset name, and so on.
50 | 51 | 52 | 53 | The CNN module pre-train output is a csv file, which format with: 54 | 55 | `{f1,f2,f3...,predict_label,true_label,quality_factory}`, where f1,f2... is CNN confidence of each camera model. 56 | 57 | 3. Post-train in `experiment` folder 58 | 59 |

60 | 61 | * You can train your personal pretrain model: 62 | 63 | 1. Download Drensden dataset into /code/dataset 64 | 65 | > python main.py --code.config --action download --name Dresden 66 | 67 | 2. Generate a tensorflow `records` file: 68 | 69 | > python main.py --code.config --action generator 70 | 71 | 3. For training process, running command: 72 | 73 | > python main.py --conf code.config --action train 74 | 75 | 4. Making your personal tampering dataset: 76 | 77 | > python main.py --conf code.config --action splicing 78 | 79 |
80 | 81 | # Result 82 | 83 | 84 | 85 | ![Results of comparative experiment with method proposed by Bondi et al. and our RFM method. (a)-(c) illustrates cover image, forged image, and ground truth image. (d) and (e) illustrates first iteration and output of RFM algorithm, (f) show result of Bondi et al.](https://github.com/grasses/Tampering-Detection-and-Localization/blob/master/static/result-3.jpg?raw=true) 86 | 87 | 88 | 89 | Results of comparative experiment with method proposed by Bondi et al. and our RFM method. (a)-(c) illustrates cover image, forged image, and ground truth image. (d) and (e) illustrates result of cover image and forged image with RFM algorithm, (f) show result of Bondi et al. We improve localization fineness from 64 x 64 to 32 x 32 (see (e) and (f)). 90 | 91 |
92 | 93 | # License 94 | 95 | This library is under the GPL V3 license. For the full copyright and license information, please view the LICENSE file that was distributed with this source code. 96 | -------------------------------------------------------------------------------- /code/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding:utf-8 -*- 3 | 4 | __author__ = 'grasses' 5 | __email__ = 'xiaocao.grasses@gmail.com' 6 | __copyright__ = 'Copyright © 2018/08/20, grasses' 7 | 8 | from code.config import Config 9 | from code.network import Network 10 | from code.utils import Generator 11 | 12 | __all__ = ["Config", "Network", "Test", "Train"] -------------------------------------------------------------------------------- /code/config.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding:utf-8 -*- 3 | 4 | __author__ = 'grasses' 5 | __email__ = 'xiaocao.grasses@gmail.com' 6 | __copyright__ = 'Copyright © 2018/08/19, grasses' 7 | 8 | import tensorflow as tf, os 9 | 10 | class Config(): 11 | ROOT = os.path.abspath(os.path.dirname(__file__)) 12 | 13 | # modeling 14 | label_size = 5 15 | batch_size = 256 16 | total_batch = 102400 17 | image_size = [64, 64, 3] 18 | optimizer = tf.train.AdamOptimizer 19 | scope_name = "dresden.model5" 20 | 21 | # leaning_rate 22 | decay_rate = 0.98 23 | decay_steps = 700 24 | learning_rate = 0.0018 25 | 26 | # generator 27 | test_list_size = 100 28 | min_after_dequeue = 40960 29 | dataset_name = "Dresden" 30 | input_path = os.path.join(ROOT, "dataset", dataset_name) 31 | output_path = os.path.join(ROOT, "dataset/output") 32 | 33 | train = { 34 | "summary_steps": 50, 35 | "saving_steps": 50 36 | } 37 | 38 | test = { 39 | 40 | } 41 | 42 | # Config for splicing plugin 43 | splicing = { 44 | "splice": 0.8, 45 | "stride": 32, 46 | } 47 | 48 | # Layer type. Don't change!! 49 | Conv, FC = "conv", "fc" 50 | 51 | net = { 52 | "01_Conv1": { 53 | "type": Conv, 54 | "patch_size": 8, 55 | "in_depth": 3, 56 | "out_depth": 16, 57 | "strides": [1, 1, 1, 1], 58 | }, 59 | "02_Conv2": { 60 | "type": Conv, 61 | "patch_size": 8, 62 | "in_depth": 16, 63 | "out_depth": 32, 64 | "strides": [1, 2, 2, 1], 65 | "activation": tf.nn.relu, 66 | }, 67 | "03_Conv3": { 68 | "type": Conv, 69 | "patch_size": 6, 70 | "in_depth": 32, 71 | "out_depth": 96, 72 | "strides": [1, 1, 1, 1], 73 | }, 74 | "04_Conv4": { 75 | "type": Conv, 76 | "patch_size": 6, 77 | "in_depth": 96, 78 | "out_depth": 128, 79 | "strides": [1, 1, 1, 1], 80 | "activation": tf.nn.relu, 81 | }, 82 | "05_Conv5": { 83 | "type": Conv, 84 | "patch_size": 3, 85 | "in_depth": 128, 86 | "out_depth": 256, 87 | "strides": [1, 2, 2, 1], 88 | }, 89 | "06_Conv6": { 90 | "type": Conv, 91 | "patch_size": 3, 92 | "in_depth": 256, 93 | "out_depth": 512, 94 | "strides": [1, 1, 1, 1], 95 | "activation": tf.nn.relu, 96 | }, 97 | "07_Conv7": { 98 | "type": Conv, 99 | "patch_size": 3, 100 | "in_depth": 512, 101 | "out_depth": 768, 102 | "strides": [1, 2, 2, 1], 103 | "activation": tf.nn.relu, 104 | }, 105 | "08_Conv8": { 106 | "type": Conv, 107 | "patch_size": 3, 108 | "in_depth": 768, 109 | "out_depth": 512, 110 | "strides": [1, 1, 1, 1], 111 | "activation": tf.nn.relu, 112 | }, 113 | "09_Conv9": { 114 | "type": Conv, 115 | "patch_size": 3, 116 | "in_depth": 512, 117 | "out_depth": 512, 118 | "strides": [1, 1, 1, 1], 119 | "activation": tf.nn.relu, 120 | }, 121 | "10_Conv10": { 122 | "type": Conv, 123 | "patch_size": 1, 124 | "in_depth": 512, 125 | "out_depth": 256, 126 | "strides": [1, 2, 2, 1], 127 | "activation": tf.nn.relu, 128 | }, 129 | "11_Conv11": { 130 | "type": Conv, 131 | "patch_size": 1, 132 | "in_depth": 256, 133 | "out_depth": 128, 134 | "strides": [1, 1, 1, 1], 135 | "dropout": 0.9, 136 | "activation": tf.nn.relu, 137 | }, 138 | "12_Conv12": { 139 | "type": Conv, 140 | "patch_size": 1, 141 | "in_depth": 128, 142 | "out_depth": 32, 143 | "strides": [1, 2, 2, 1], 144 | "debug": True, 145 | }, 146 | "13_FC1": { 147 | "type": FC, 148 | "in_depth": 128, 149 | "out_depth": 64, 150 | "dropout": 0.9, 151 | }, 152 | "14_FC2": { 153 | "type": FC, 154 | "in_depth": 64, 155 | "out_depth": 32, 156 | "activation": tf.nn.relu, 157 | }, 158 | "15_FC3": { 159 | "type": FC, 160 | "in_depth": 32, 161 | "out_depth": label_size, 162 | "debug": True, 163 | } 164 | } 165 | 166 | name_list = ["01_Conv1", "02_Conv2", "03_Conv3", "04_Conv4", "05_Conv5", "06_Conv6", "07_Conv7", "08_Conv8", 167 | "09_Conv9", "10_Conv10", "11_Conv11", "12_Conv12", "13_FC1", "14_FC2", "15_FC3"] 168 | 169 | ''' 170 | Note of decay dropout: 171 | decayed_learning_rate = learning_rate * decay_rate ^ (global_step / decay_steps) 172 | decayed_dropout_rate = decayed_dropout + decay_impact * decayed_learning_rate 173 | ''' -------------------------------------------------------------------------------- /code/network.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding:utf-8 -*- 3 | 4 | __author__ = 'grasses' 5 | __email__ = 'xiaocao.grasses@gmail.com' 6 | __copyright__ = 'Copyright © 2018/08/19, grasses' 7 | 8 | from code.config import Config 9 | import code.utils.tools as utils, time, os, tensorflow as tf, numpy as np 10 | curr_path = os.path.dirname(os.path.realpath(__file__)) 11 | 12 | class Network(object): 13 | def __init__(self, conf=Config): 14 | self._conf = conf 15 | 16 | # tensorboard 17 | self.merged = None 18 | self.summaries = [] 19 | self.merged_summary = [] 20 | self.writer = None 21 | self.writer_path = "{:s}/board/{:s}".format(curr_path, self._conf.scope_name) 22 | 23 | # model saver 24 | self.saver = None 25 | self.save_path = "{:s}/model/{:s}/model/model.ckpt".format(curr_path, self._conf.scope_name) 26 | 27 | # params 28 | self.conv_weights = [] 29 | self.conv_biases = [] 30 | self.fc_weights = [] 31 | self.fc_biases = [] 32 | self.params_key = [] 33 | self.params_value = [] 34 | 35 | # network common params 36 | self.X = None 37 | self.Y = None 38 | self.logits = None 39 | 40 | # init function 41 | self.model_path = "{:s}/model/{:s}/".format(curr_path, self._conf.scope_name) 42 | utils.rebuild(self.model_path) 43 | 44 | def apply_regularization(self, _lambda=5e-4): 45 | # L2 regularization for the fully connected parameters 46 | regularization = 0.0 47 | for weights, biases in zip(self.fc_weights, self.fc_biases): 48 | regularization += tf.nn.l2_loss(weights) + tf.nn.l2_loss(biases) 49 | return _lambda * regularization 50 | 51 | def xavier_init(self, in_size, out_size, constant=1.0): 52 | # for detail see paper: http://proceedings.mlr.press/v9/glorot10a/glorot10a.pdf 53 | low = -constant * np.sqrt(6.0 / (in_size + out_size)) 54 | high = constant * np.sqrt(6.0 / (in_size + out_size)) 55 | return tf.random_uniform((in_size, out_size), minval=low, maxval=high, dtype=tf.float32) 56 | 57 | def add_cnn(self, name, kernel, value=0.1, stddev=0.1): 58 | ''' 59 | :param name: layer name 60 | :param kernel: kernel size [patch_size, in_size, out_size] 61 | :param stddev: stddev of w 62 | :return: (w, b) 63 | ''' 64 | w = tf.Variable(tf.truncated_normal(kernel, stddev=stddev), name="{:s}_weights".format(name)) 65 | b = tf.Variable(tf.constant(value=value, shape=[kernel[3]]), name="{:s}_biases".format(name)) 66 | self.conv_weights.append(w) 67 | self.conv_biases.append(b) 68 | return (w, b) 69 | 70 | def add_fc(self, name, in_depth, out_depth, value=0.1): 71 | ''' 72 | :param name: layer name 73 | :param in_depth: fully connected in size 74 | :param out_depth: fully connected out size 75 | :param value: init value 76 | :return: (w, b) 77 | ''' 78 | w = tf.Variable(self.xavier_init(in_depth, out_depth), name="{:s}_weights".format(name)) 79 | b = tf.Variable(tf.constant(value=value, shape=[out_depth], name="{:s}_biases".format(name))) 80 | self.fc_weights.append(w) 81 | self.fc_biases.append(b) 82 | return (w, b) 83 | 84 | def has_model(self): 85 | return os.path.exists(self.save_path + ".meta") 86 | 87 | def model(self, X, is_train=True): 88 | seed = int(time.time()) 89 | print("=> X={:s}".format(X.get_shape().as_list())) 90 | 91 | with tf.name_scope("leaning_rate"): 92 | self.global_step = tf.Variable(0, trainable=False, name="global_step") 93 | self.learning_rate = tf.train.exponential_decay( 94 | learning_rate=self._conf.learning_rate, 95 | global_step=self.global_step, 96 | decay_steps=self._conf.decay_steps, 97 | decay_rate=self._conf.decay_rate, 98 | staircase=True 99 | ) 100 | # decayed_learning_rate = learning_rate * decay_rate ^ (global_step / decay_steps) 101 | # decayed_dropout_rate = base + decay_impact * decayed_learning_rate 102 | 103 | self.X = X 104 | 105 | # for (name, _) in sorted(self._conf.net.items(), key=lambda x: x[0: 2]): 106 | # item = utils.to_obj(_) 107 | 108 | for name in self._conf.name_list: 109 | _ = self._conf.net[name] 110 | item = utils.to_obj(_) 111 | 112 | with tf.name_scope(name): 113 | if item.type == Config.Conv: 114 | (w, b) = self.add_cnn(name, [item.patch_size, item.patch_size, item.in_depth, item.out_depth]) 115 | X = tf.nn.conv2d(X, filter=w, strides=item.strides, padding="SAME") + b 116 | elif item.type == Config.FC: 117 | shape = X.get_shape().as_list() 118 | if len(shape) > 2: 119 | X = tf.reshape(X, [-1, shape[1] * shape[2] * shape[3]]) 120 | (w, b) = self.add_fc(name, item.in_depth, item.out_depth) 121 | X = tf.matmul(X, w) + b 122 | 123 | # activation layer 124 | if _.has_key("activation") and _["activation"]: 125 | X = _["activation"](X) 126 | 127 | # pooling layer 128 | if _.has_key("pooling") and _["pooling"]: 129 | X = _["pooling"]( 130 | X, 131 | ksize=item.pooling_ksize, 132 | strides=item.pooling_strides, 133 | padding=item.pooling_padding 134 | ) 135 | 136 | # dropout layer 137 | if _.has_key("dropout") and _["dropout"]: 138 | X = tf.nn.dropout(X, keep_prob=item.dropout, seed=seed) if is_train else X / item.dropout 139 | 140 | # decay dropout 141 | if _.has_key("decay_dropout"): 142 | dropout = item.decay_dropout + ((1 - item.decay_dropout) * (self.learning_rate/ self._conf.learning_rate)) 143 | X = tf.nn.dropout(X, keep_prob=dropout, seed=seed) if is_train else X / dropout 144 | self.summaries.append(tf.summary.scalar("decay_dropout", dropout)) 145 | 146 | # save in debug params 147 | if _.has_key("debug") and _["debug"]: 148 | self.params_key.append(name) 149 | self.params_value.append(X) 150 | 151 | print("=> name={:s} X={:s}".format(name, X.get_shape().as_list())) 152 | self.logits = X 153 | return self 154 | 155 | def optimizer(self, Y): 156 | self.Y = Y 157 | with tf.name_scope("loss"): 158 | # loss 159 | self.loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(logits=self.logits, labels=self.Y)) 160 | self.loss += self.apply_regularization(_lambda=5e-4) 161 | 162 | with tf.name_scope("accuracy"): 163 | # prediction 164 | self.output = tf.nn.softmax(logits=self.logits, name="output") 165 | self.predict = tf.argmax(self.output, axis=1) 166 | 167 | # accuracy 168 | accuracy_op = tf.equal(tf.argmax(self.output, axis=1), tf.argmax(self.Y, axis=1)) 169 | self.accuracy = 100 * tf.reduce_mean(tf.cast(accuracy_op, tf.float32)) 170 | 171 | with tf.name_scope("optimizer"): 172 | if self._conf.optimizer == tf.train.MomentumOptimizer: 173 | self.optimizer = tf.train.MomentumOptimizer(learning_rate=self.learning_rate, momentum=0.5).minimize(self.loss, global_step=self.global_step) 174 | elif self._conf.optimizer == tf.train.AdamOptimizer: 175 | self.optimizer = tf.train.AdamOptimizer(learning_rate=self.learning_rate).minimize(loss=self.loss, global_step=self.global_step) 176 | 177 | # add summary 178 | self.summaries.append(tf.summary.scalar("accuracy", self.accuracy)) 179 | self.summaries.append(tf.summary.scalar("loss", self.loss)) 180 | # merged summary 181 | self.merged_summary = tf.summary.merge(self.summaries) 182 | # save graph 183 | self.saver = tf.train.Saver(tf.global_variables()) 184 | return self 185 | 186 | def train(self, X, Y, G_X, G_Y): 187 | ''' 188 | :param X: placeholder for X 189 | :param Y: placeholder for Y 190 | :param G_X: tfrecords generator X 191 | :param G_Y: tfrecords generator Y 192 | :param G_name: tfrecords generator name 193 | :return: null 194 | ''' 195 | self.model(X).optimizer(Y) 196 | with tf.Session() as session: 197 | self.writer = tf.summary.FileWriter(logdir=self.writer_path, graph=session.graph) 198 | if not self.has_model(): 199 | session.run(tf.global_variables_initializer()) 200 | else: 201 | print("=> loading session from: {:s}".format(self.save_path)) 202 | self.saver.restore(session, self.save_path) 203 | 204 | tf.train.start_queue_runners(sess=session, coord=tf.train.Coordinator()) 205 | global_step = session.graph.get_tensor_by_name("leaning_rate/global_step:0") 206 | for index in range(global_step.eval(), self._conf.total_batch): 207 | (samples, labels) = session.run([G_X, G_Y]) 208 | # _X = np.reshape(G.normalize(samples), [self.batch_size, self.image_size * self.image_size * 3]) 209 | (_X, _Y) = (utils.normalize(samples), utils.reformat(labels, self._conf.label_size)) 210 | 211 | (_, params, predict, loss, accuracy, output, summary) = session.run( 212 | [self.optimizer, self.params_value, self.predict, self.loss, self.accuracy, self.output, self.merged_summary], 213 | feed_dict={ 214 | self.X: _X, 215 | self.Y: _Y 216 | } 217 | ) 218 | 219 | if index % self._conf.train["summary_steps"] == 0: 220 | self.writer.add_summary(summary, index) 221 | self.writer.flush() 222 | if index % self._conf.train["saving_steps"] == 0: 223 | for i in range(len(self.params_key)): 224 | print("=> {:s} -> {:s}".format(self.params_key[i], str(params[i][0]))) 225 | print("=> step={:d}, loss={:.5f}, accuracy:{:.3f}%".format(index, loss, accuracy)) 226 | if len(params) > 0: 227 | print("\n\n\n") 228 | self.saver.save(session, self.save_path) 229 | 230 | def iterator_train(self, X, Y, iterator): 231 | self.model(X).optimizer(Y) 232 | with tf.Session() as session: 233 | self.writer = tf.summary.FileWriter(logdir=self.writer_path, graph=session.graph) 234 | if not self.has_model(): 235 | session.run(tf.global_variables_initializer()) 236 | else: 237 | print("=> loading session from: {:s}".format(self.save_path)) 238 | self.saver.restore(session, self.save_path) 239 | 240 | global_step = session.graph.get_tensor_by_name("leaning_rate/global_step:0") 241 | for index in range(global_step.eval(), self._conf.total_batch): 242 | for (count, step_count, samples, labels) in iterator(): 243 | (_X, _Y) = (utils.normalize(samples), utils.reformat(labels, self._conf.label_size)) 244 | 245 | (_, params, predict, loss, accuracy, output, summary) = session.run( 246 | [self.optimizer, self.params_value, self.predict, self.loss, self.accuracy, self.output, self.merged_summary], 247 | feed_dict={ 248 | self.X: _X, 249 | self.Y: _Y 250 | } 251 | ) 252 | if step_count % self._conf.train["summary_steps"] == 0: 253 | self.writer.add_summary(summary, index) 254 | self.writer.flush() 255 | if step_count % self._conf.train["saving_steps"] == 0: 256 | for i in range(len(self.params_key)): 257 | print("=> {:s} -> {:s}".format(self.params_key[i], str(params[i][0]))) 258 | print("=> step={:d}, loss={:.5f}, accuracy:{:.3f}%".format(index, loss, accuracy)) 259 | if len(params) > 0: 260 | print("\n\n\n") 261 | self.saver.save(session, self.save_path) 262 | 263 | if __name__ == "__main__": 264 | X = tf.placeholder(tf.float32, shape=(256, 64, 64, 3), name="X") 265 | Y = tf.placeholder(tf.float32, shape=(256, 5), name="Y") 266 | 267 | N = Network() 268 | N.model(X).optimizer(Y) -------------------------------------------------------------------------------- /code/test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding:utf-8 -*- 3 | 4 | __author__ = 'grasses' 5 | __email__ = 'xiaocao.grasses@gmail.com' 6 | __copyright__ = 'Copyright © 2018/08/20, grasses' 7 | 8 | from code.config import Config 9 | from code.network import Network 10 | from code.utils.splicing import Splicing 11 | import os, tensorflow as tf, numpy as np, pandas as pd, utils.tools as utils 12 | curr_path = os.path.dirname(os.path.realpath(__file__)) 13 | 14 | class Test(object): 15 | def __init__(self, net=Network(conf=Config)): 16 | self.net = net 17 | self._conf = net._conf 18 | self.save_path = net.save_path 19 | self.model_path = os.path.join(curr_path, "model", self._conf.scope_name) 20 | 21 | # network params 22 | self.X = tf.placeholder(tf.float32, shape=[self._conf.batch_size, 64, 64, 3], name="X") 23 | self.Y = tf.placeholder(tf.float32, shape=[self._conf.batch_size, self._conf.label_size], name="Y") 24 | 25 | def run(self, iterator, is_true_test=False): 26 | if not self.net.has_model(): 27 | print("=> Please train your model first!!") 28 | exit(1) 29 | 30 | # build graph 31 | self.net.model(self.X).optimizer(self.Y) 32 | with tf.Session() as session: 33 | # restore session 34 | print("=> loading session from: {:s}".format(self.net.save_path)) 35 | self.net.saver.restore(session, self.net.save_path) 36 | 37 | # file iterator 38 | pre_output = [] 39 | 40 | for (index, flag, name, X, Y, Q, tamper_rate, shape, offset_x, offset_y, width, height) in iterator(): 41 | (_X, _Y) = (utils.normalize(X), utils.reformat(Y, self._conf.label_size)) 42 | (params, softmax, loss, predict, accuracy) = session.run( 43 | [self.net.params_value, self.net.output, self.net.loss, self.net.predict, self.net.accuracy], 44 | feed_dict={ 45 | self.X: _X, 46 | self.Y: _Y 47 | } 48 | ) 49 | # tmp = [softmax(*label_size), predict, label, confidence] 50 | tmp = np.zeros([256, 8], dtype=np.float32) 51 | tmp[:, 0: 5] = softmax 52 | tmp[:, 5] = predict 53 | tmp[:, 6] = Y 54 | tmp[:, 7] = Q 55 | tmp = np.reshape(tmp, (-1, 8)) 56 | pre_output.append(tmp) 57 | 58 | # save result into csv file 59 | if index == flag: 60 | pre_output = np.array(pre_output, dtype=np.float32) 61 | name = "{:s}_{:d}_{:d}".format(name, width, height) 62 | df = pd.DataFrame(np.reshape(pre_output, (-1, 8))) 63 | print(df.shape) 64 | 65 | if not is_true_test: 66 | csv_path = os.path.join(self.model_path, "pre-train", "{:s}.csv".format(name)) 67 | else: 68 | csv_path = os.path.join(self.model_path, "pre-train-true", "{:s}.csv".format(name)) 69 | print("=> save pretrain at csv_path={:s}".format(csv_path)) 70 | df.to_csv(csv_path) 71 | pre_output = [] 72 | 73 | for i in range(len(predict)): 74 | if predict[i] != Y[i]: 75 | print("=> index={:d} p={:d} Y={:d} tamper_rate={:.5f} output={:s}".format(i, predict[i], Y[i], tamper_rate[i], softmax[i])) 76 | print("=> ({:d}, {:d}), loss={:.5f}, accuracy:{:.3f}% \n".format(index, flag, loss, accuracy)) 77 | if len(params) > 0: print("\n\n") 78 | 79 | print("=> pretrain csv format={f1,f2,f3...,predict,label,texture_quality}, f1,f2 is CNN confidence for each model\n") 80 | 81 | def main(conf=Config): 82 | S = Splicing(conf=conf) 83 | T = Test(net=Network(conf=conf)) 84 | T.run(S.iterator) 85 | 86 | if __name__ == "__main__": 87 | main() -------------------------------------------------------------------------------- /code/train.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding:utf-8 -*- 3 | 4 | __author__ = 'grasses' 5 | __email__ = 'xiaocao.grasses@gmail.com' 6 | __copyright__ = 'Copyright © 2018/08/20, grasses' 7 | 8 | from code.config import Config 9 | from code.network import Network 10 | from code.utils import Generator, tools 11 | import tensorflow as tf 12 | 13 | def main(conf=Config): 14 | tools.backup(conf) 15 | 16 | X = tf.placeholder(tf.float32, shape=[256, 64, 64, 3], name="X") 17 | Y = tf.placeholder(tf.float32, shape=[256, Config.label_size], name="Y") 18 | 19 | # Generator feeding data 20 | G = Generator(conf=conf) 21 | (G_X, G_Y, G_name, G_offset_x, G_offset_y, G_noise) = G.read() 22 | 23 | # Network building graph 24 | N = Network(conf=conf) 25 | N.train(X, Y, G_X, G_Y) 26 | 27 | if __name__ == "__main__": 28 | main() -------------------------------------------------------------------------------- /code/utils/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding:utf-8 -*- 3 | 4 | __author__ = 'grasses' 5 | __email__ = 'xiaocao.grasses@gmail.com' 6 | __copyright__ = 'Copyright © 2018/08/19, grasses' 7 | 8 | from splicing import Splicing 9 | from generator import Generator 10 | import tools 11 | 12 | __all__ = ["Splicing", "Generator", "tools"] -------------------------------------------------------------------------------- /code/utils/download.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | __author__ = 'grasses' 5 | __email__ = 'xiaocao.grasses@gmail.com' 6 | __copyright__ = 'Copyright © 2018/11/07, grasses' 7 | 8 | import os, requests 9 | 10 | class Download(): 11 | def __init__(self, conf, name="Dresden"): 12 | self._conf = conf 13 | self._name = name 14 | self._dataset_root = os.path.join(self._conf.ROOT, "dataset") 15 | self._dataset_path = os.path.join(self._dataset_root, self._name) 16 | 17 | self.url_path = os.path.join(self._dataset_root, self._name + ".txt") 18 | if not os.path.exists(self.url_path): 19 | raise Exception("Dataset url file `{:s}` not exists!".format(self.url_path)) 20 | self.rebuild() 21 | 22 | def rebuild(self): 23 | try: 24 | if not os.path.exists(self._dataset_path): 25 | os.mkdir(self._dataset_path, 0755) 26 | except Exception as e: 27 | print("=> error:{:s}".format(str(e))) 28 | 29 | def build_path(self, factory, model): 30 | try: 31 | factory_path = os.path.join(self._dataset_path, factory) 32 | model_path = os.path.join(factory_path, model) 33 | if not os.path.exists(factory_path): 34 | os.mkdir(factory_path, 0755) 35 | if not os.path.exists(model_path): 36 | os.mkdir(model_path, 0755) 37 | except Exception as e: 38 | print("=> error:{:s}".format(str(e))) 39 | 40 | def download(self, url, factory, model, name): 41 | with open(os.path.join(self._dataset_path, factory, model, name), "wb") as fp: 42 | response = requests.get(url, stream=True) 43 | if not response.ok: 44 | fp.close() 45 | return False 46 | 47 | for block in response.iter_content(1024): 48 | if not block: 49 | break 50 | fp.write(block) 51 | fp.close() 52 | return True 53 | 54 | def run(self, debug=False): 55 | errors = [] 56 | with open(self.url_path, "r+") as fp: 57 | while True: 58 | line = fp.readline().rstrip("\n") 59 | name = line.split("/")[-1] 60 | factory, model = name.split("_")[0], name.split("_")[1] 61 | 62 | self.build_path(factory, model) 63 | result = self.download(line, factory, model, name) 64 | 65 | if debug: print(line) 66 | if not result: errors.append(line) 67 | if not line: break 68 | return errors -------------------------------------------------------------------------------- /code/utils/generator.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | __author__ = 'grasses' 5 | __email__ = 'xiaocao.grasses@gmail.com' 6 | __copyright__ = 'Copyright © 2018/08/20, grasses' 7 | 8 | import tensorflow as tf, numpy as np, os, tools, json, random, cv2 9 | from code.config import Config 10 | curr_path = os.path.abspath(os.path.dirname(__file__)) 11 | parent_path = os.path.abspath(os.path.dirname(curr_path)) 12 | 13 | class Generator(object): 14 | def __init__(self, conf=Config, debug=False): 15 | self._conf = conf 16 | self.debug = debug 17 | 18 | # saving params 19 | self.config = { 20 | "model_label": {}, 21 | "label_model": {}, 22 | "train_list": {}, 23 | "test_list": {}, 24 | "label_path": {}, 25 | "train_label_count": {}, 26 | "test_label_count": {}, 27 | "scope_name": self._conf.scope_name, 28 | "label_count": self._conf.label_size, 29 | 30 | # dataset 31 | "dataset_name": conf.dataset_name, 32 | 33 | # network 34 | "decay_rate": conf.decay_rate, 35 | "decay_steps": conf.decay_steps, 36 | "learning_rate": conf.learning_rate, 37 | } 38 | 39 | self.records_path = "{:s}/{:s}.tfrecords".format(self._conf.output_path, self._conf.scope_name) 40 | self.model_path = os.path.join(parent_path, "model", self._conf.scope_name) 41 | tools.rebuild(self.model_path) 42 | 43 | def read_db(self): 44 | if os.path.exists(os.path.join(self.model_path, "db.json")): 45 | with open(os.path.join(self.model_path, "db.json"), "r+") as f: 46 | data = f.read() 47 | try: 48 | self.config = json.loads(data) 49 | except Exception as e: 50 | print(e) 51 | finally: 52 | f.close() 53 | return True 54 | return False 55 | 56 | def write_db(self): 57 | with open(os.path.join(self.model_path, "db.json"), "w+") as f: 58 | f.write(json.dumps(self.config)) 59 | f.close() 60 | return self 61 | 62 | def read_directory(self): 63 | if self.read_db(): return self 64 | tools.remove_dirty(self._conf.input_path) 65 | 66 | count = 0 67 | for factory in sorted(os.listdir(self._conf.input_path)): 68 | tmp_path = os.path.join(self._conf.input_path, factory) 69 | try: 70 | for name in sorted(os.listdir(tmp_path)): 71 | model = "{:s}_{:s}".format(factory, name) 72 | model_dir = "{:s}/{:s}".format(tmp_path, name) 73 | if not os.path.isdir(model_dir): 74 | os.remove(model_dir) 75 | continue 76 | self.config["model_label"][model] = count 77 | self.config["label_model"][count] = model 78 | self.config["test_label_count"][str(count)] = 0 79 | self.config["train_label_count"][str(count)] = 0 80 | self.config["label_path"][str(count)] = "{:s}/{:s}".format(factory, name) 81 | count += 1 82 | except Exception as e: 83 | print("=> [error] read_directory() e={:s}".format(e)) 84 | self.config["label_count"] = count 85 | 86 | # push into self.config["train_list"] 87 | for (label, path) in self.config["label_path"].items(): 88 | tools.remove_dirty(os.path.join(self._conf.input_path, path)) 89 | 90 | tmp_list = os.listdir(os.path.join(self._conf.input_path, path)) 91 | self.config["train_list"][str(label)] = tmp_list 92 | self.config["train_label_count"][str(label)] = len(tmp_list) 93 | 94 | # push into self.config["test_list"] 95 | for (label, file_list) in self.config["train_list"].items(): 96 | label = str(label) 97 | self.config["test_list"][label] = [] 98 | 99 | if len(file_list) <= self._conf.test_list_size: 100 | print("=> read_directory() {:s} not enough file for testing".format(self.config["label_model"][int(label)])) 101 | exit(1) 102 | 103 | for i in range(self._conf.test_list_size): 104 | fid = random.randint(0, len(self.config["train_list"][label]) - 1) 105 | self.config["test_list"][label].append(file_list[fid]) 106 | self.config["test_label_count"][label] += 1 107 | # write into file_list 108 | self.write_db() 109 | return self 110 | 111 | ''' 112 | private function 113 | ''' 114 | def iterator_read(self, is_train=True): 115 | self.read_directory() 116 | count = 1 117 | shape = self._conf.image_size 118 | 119 | while True: 120 | file_list = self.config["train_list"] 121 | if not is_train: 122 | file_list = self.config["test_list"] 123 | rand_label = str(random.randint(0, self.config["label_count"] - 1)) 124 | 125 | # skip file_list[label] = null 126 | if len(file_list[rand_label]) == 0: continue 127 | 128 | rand_fid = random.randint(0, len(file_list[rand_label]) - 1) 129 | file_name = file_list[rand_label][rand_fid] 130 | model_path = self.config["label_path"][rand_label] 131 | full_name = os.path.join(model_path, file_name) 132 | 133 | if self.debug: 134 | print("=> iterator_read(), count={:d} filename={:s}".format(count, file_name)) 135 | 136 | image = cv2.imread(os.path.join(self._conf.input_path, full_name)) 137 | (w, h) = (int(image.shape[1] / shape[1]), int(image.shape[0] / shape[0])) 138 | print(full_name, w, h) 139 | 140 | for j in range(h): 141 | for i in range(w): 142 | data = (image[j: j + shape[0], i: i + shape[1], :]).copy() 143 | noise = tools.confidence(data) 144 | yield(data, int(rand_label), full_name, i * shape[1], j * shape[0], noise) 145 | count += 1 146 | del file_list[rand_label][rand_fid] 147 | 148 | # if run all images: break loop 149 | tmp_count = 0 150 | for i in range(len(file_list)): 151 | if len(file_list[str(i)]) == 0: 152 | tmp_count += 1 153 | if tmp_count == self.config["label_count"]: break 154 | print("=> iterator over") 155 | 156 | ''' 157 | private function 158 | ''' 159 | def read_and_decode(self): 160 | reader = tf.TFRecordReader() 161 | filename_queue = tf.train.string_input_producer([self.records_path]) 162 | (_, serialized_example) = reader.read(filename_queue) 163 | features = tf.parse_single_example( 164 | serialized_example, 165 | features={ 166 | "offset_x": tf.FixedLenFeature([], tf.int64), 167 | "offset_y": tf.FixedLenFeature([], tf.int64), 168 | "image_label": tf.FixedLenFeature([], tf.int64), 169 | "image_noise": tf.FixedLenFeature([], tf.float32), 170 | "image_data": tf.FixedLenFeature([], tf.string), 171 | "image_name": tf.FixedLenFeature([], tf.string) 172 | } 173 | ) 174 | X = tf.reshape(tf.cast(tf.decode_raw(features["image_data"], tf.uint8), tf.float32), shape=self._conf.image_size) 175 | Y = tf.cast(features["image_label"], tf.int32) 176 | (name, image_noise) = (tf.cast(features["image_name"], tf.string), tf.cast(features["image_noise"], tf.float32)) 177 | (offset_x, offset_y) = (tf.cast(features["offset_x"], tf.int32), tf.cast(features["offset_y"], tf.int32)) 178 | return (X, Y, name, offset_x, offset_y, image_noise) 179 | 180 | 181 | def crop(self, image, shape, index): 182 | (x_max, y_max) = int(image.shape[1] / shape[1]), int(image.shape[0] / shape[0]) 183 | 184 | if index >= x_max * y_max: 185 | print(index, x_max, y_max) 186 | return (None, None, None) 187 | 188 | offset_x, offset_y = int(index % x_max * shape[1]), int(index / x_max * shape[0]) 189 | data = image[offset_y: offset_y + shape[1], offset_x: offset_x + shape[0]].copy() 190 | return (data, offset_x, offset_y) 191 | 192 | 193 | # ========================================public interface============================================== # 194 | 195 | def test_iterator(self): 196 | count, index = 0, 0 197 | X, Y = [], [] 198 | for (x, y, name, offset_x, offset_y, noise) in self.iterator_read(is_train=False): 199 | if index % self._conf.batch_size == 0: 200 | count += 1 201 | if index > 0: 202 | yield(count, np.array(X, dtype=np.float32), np.array(Y, dtype=np.int32)) 203 | X, Y = [], [] 204 | 205 | X.append(x) 206 | Y.append(y) 207 | index += 1 208 | 209 | def file_iterator(self, size=None): 210 | ''' 211 | 这个函数主要针对训练,返回训练集中数据;不针对测试,因为不包含图像质量Q、偏移量; 212 | 需要test接口,需要到Splicing.file_iterator 213 | ''' 214 | self.read_directory() 215 | shape = self._conf.image_size 216 | 217 | training_list = [] 218 | for (label, names) in self.config["train_list"].items(): 219 | for item in names: 220 | training_list.append([item, int(label)]) 221 | random.shuffle(training_list) 222 | 223 | count = 0 224 | step_count = 0 225 | for (image_name, label) in training_list: 226 | names = image_name.split("_") 227 | print("=> {:s}/{:s}/{:s}/{:s}".format(self._conf.input_path, names[0], names[1], image_name)) 228 | image = cv2.imread("{:s}/{:s}/{:s}/{:s}".format(self._conf.input_path, names[0], names[1], image_name)) 229 | 230 | (x_max, y_max) = int(image.shape[1] / shape[1]), int(image.shape[0] / shape[0]) 231 | max_patch = x_max * y_max 232 | 233 | (data, offset_x, offset_y) = ([], None, None) 234 | # 针对图像总数循环 235 | for index in range(max_patch / self._conf.batch_size + 1): 236 | (x, y) = [], [] 237 | # 针对batch_size循环 238 | for i in range(self._conf.batch_size): 239 | (_data, _offset_x, _offset_y) = self.crop(image, shape, index) 240 | if type(_data) == np.ndarray: 241 | data = _data 242 | else: 243 | print(i, type(_data)) 244 | x.append(data), y.append(int(label)) 245 | step_count += 1 246 | yield (count, step_count, np.array(x, dtype=np.float32), np.array(y, dtype=np.int32)) 247 | print("=> count={:d} step_count={:d}".format(count, step_count)) 248 | count += 1 249 | if size and size > count: return 250 | 251 | ''' 252 | [public funtion] write file into tfrecord, interface from self.iterator_read() 253 | :param [image_data, image_label, image_name, offset_x, offset_y, image_noise] 254 | ''' 255 | def write(self): 256 | self.writer = tf.python_io.TFRecordWriter(self.records_path) 257 | for (image_data, image_label, image_name, offset_x, offset_y, image_noise) in self.iterator_read(): 258 | example = tf.train.Example( 259 | features=tf.train.Features( 260 | feature={ 261 | "offset_x": tools._int64_feature(offset_x), 262 | "offset_y": tools._int64_feature(offset_y), 263 | "image_label": tools._int64_feature(image_label), 264 | "image_noise": tools._float32_feature(image_noise), 265 | "image_data": tools._bytes_feature(image_data.tostring()), 266 | "image_name": tools._bytes_feature(str(image_name)) 267 | } 268 | ) 269 | ) 270 | self.writer.write(example.SerializeToString()) 271 | 272 | ''' 273 | public read interface for tfrecord file, don`t forget to iterator read by tf.Session() 274 | :param min_after_dequeue int queue cahce in memory, a control to shuffle_batch size 275 | :return [X, Y, name] name is origin image name 276 | ''' 277 | def read(self): 278 | capacity = self._conf.min_after_dequeue * 4 279 | (_image, _label, _batch_name, _offset_x, _offset_y, _image_noise) = self.read_and_decode() 280 | (_X, _Y, _name, offset_x, offset_y, noise) = tf.train.shuffle_batch( 281 | [_image, _label, _batch_name, _offset_x, _offset_y, _image_noise], 282 | batch_size=self._conf.batch_size, 283 | capacity=capacity, 284 | min_after_dequeue=self._conf.min_after_dequeue, 285 | num_threads=3 286 | ) 287 | return (_X, _Y, _name, offset_x, offset_y, noise) -------------------------------------------------------------------------------- /code/utils/splicing.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | __author__ = 'grasses' 5 | __email__ = 'xiaocao.grasses@gmail.com' 6 | __copyright__ = 'Copyright © 2018/07/10, grasses' 7 | 8 | import os, sys, cv2, time, json, ntpath, random, threading, numpy as np 9 | from code.config import Config 10 | from code.utils import tools 11 | 12 | drawing, mode, flag = False, True, False 13 | times, offset_x, offset_y = 4, 0, 0 14 | offset1, offset2 = 0, 0 15 | _x_, _y_, musk_x, musk_y = 0, 0, 0, 0 16 | 17 | curr_path = os.path.abspath(os.path.dirname(__file__)) 18 | parent_path = os.path.abspath(os.path.dirname(curr_path)) 19 | (image1, image2, musk_image, musk_shape) = (None, None, None, None) 20 | 21 | def get_mask_image(image, musk, _x, _y, with_ground_truth=False): 22 | ''' 23 | :param (_x, _y) current mouse position 24 | :param (_x_, _y_) last time mouse position 25 | :param (musk_x, musk_y) musk image position, maybe negative when mouse negative 26 | :param (musk_start_x, musk_start_y) / (musk_stop_x, musk_stop_y) crop musk position 27 | :param (image_start_x, image_start_y) / (image_stop_x, image_stop_y) crop image as background position 28 | :return: new image with object splicing image 29 | ''' 30 | global _x_, _y_, musk_x, musk_y 31 | 32 | musk_x, musk_y = _x - _x_ + musk_x, _y - _y_ + musk_y 33 | _x_, _y_ = _x, _y 34 | 35 | musk_start_x, musk_start_y, musk_stop_x, musk_stop_y = 0, 0, musk.shape[1], musk.shape[0] 36 | image_start_x, image_start_y, image_stop_x, image_stop_y = musk_x, musk_y, musk.shape[1] + musk_x, musk.shape[0] + musk_y 37 | 38 | shape = list(musk.shape) 39 | # mouse x overflow 40 | if _x + shape[1] > image.shape[1]: 41 | musk_stop_x = image.shape[1] - musk_x 42 | image_stop_x = image.shape[1] 43 | shape[1] = image.shape[1] - _x 44 | 45 | # mouse y overflow 46 | if _y + shape[0] > image.shape[0]: 47 | musk_stop_y = image.shape[0] - musk_y 48 | image_stop_y = image.shape[0] 49 | 50 | shape[0] = image.shape[0] - _y 51 | 52 | # mouse x negative 53 | if musk_x < 0: 54 | image_start_x = 0 55 | musk_start_x = -musk_x 56 | shape[1] = musk.shape[1] + musk_x 57 | 58 | # mouse y negative 59 | if musk_y < 0: 60 | image_start_y = 0 61 | musk_start_y = -musk_y 62 | shape[0] = musk.shape[0] + musk_y 63 | 64 | shape = tuple(shape) 65 | _musk = (musk[musk_start_y: musk_stop_y, musk_start_x: musk_stop_x, :]).copy() 66 | 67 | tmp_musk = np.zeros(shape, dtype=np.uint8) 68 | tmp_musk[_musk == [0, 0, 0]] = 1 69 | 70 | tmp_image = image[image_start_y: image_stop_y, image_start_x: image_stop_x, :] 71 | tmp_image = tmp_image * tmp_musk[:, :, :] 72 | tmp_image += _musk 73 | 74 | image[image_start_y: image_stop_y, image_start_x: image_stop_x, :] = tmp_image 75 | 76 | if with_ground_truth: 77 | '''get ground truth image''' 78 | image_ground = np.ones(image.shape, dtype=np.uint8) * 255 79 | tmp_musk = np.ones(shape, dtype=np.uint8) * 255 80 | tmp_musk[_musk != 0] = 0 81 | image_ground[image_start_y: image_stop_y, image_start_x: image_stop_x, :] = tmp_musk[:, :, :] 82 | return (image, image_ground) 83 | return image 84 | 85 | def get_ground_truth2(image, musk, _x, _y): 86 | shape = musk.shape 87 | 88 | if _x + shape[1] > image.shape[1]: shape[1] = image.shape[1] - _x 89 | if _y + shape[0] > image.shape[0]: shape[0] = image.shape[0] - _y # shape = [image.shape[0] - _y, shape[1], 3] 90 | 91 | if _x - shape[1] < 0: shape[1] = shape[1] - _x 92 | if _y - shape[0] < 0: shape = [shape[0] - _y, shape[1], 3] 93 | 94 | image_save = image.copy() 95 | _musk = musk[0: shape[0], 0: shape[1], :].copy() 96 | 97 | '''get splicing image''' 98 | tmp_musk = np.zeros(shape, dtype=np.uint8) 99 | tmp_musk[_musk == 0] = 1 100 | 101 | tmp_image = image[_y: _y + shape[0], _x: _x + shape[1], :] 102 | tmp_image = tmp_image * tmp_musk[:, :, :] 103 | tmp_image += _musk 104 | image_save[_y: _y + shape[0], _x: _x + shape[1], :] = tmp_image 105 | 106 | '''get ground truth image''' 107 | image_ground = np.ones(image.shape, dtype=np.uint8) * 255 108 | tmp_musk = np.ones(shape, dtype=np.uint8) * 255 109 | tmp_musk[_musk != 0] = 0 110 | image_ground[_y: _y + shape[0], _x: _x + shape[1], :] = tmp_musk[:, :, :] 111 | return (image_save, image_ground) 112 | 113 | def resize_image(image): 114 | global times 115 | return cv2.resize(image, (int(image.shape[1] / times), int(image.shape[0] / times))) 116 | 117 | def resize_list(_, times): 118 | data = [] 119 | for i in range(len(_)): 120 | data.append(int(int(_[i]) * times)) 121 | return data 122 | 123 | def find_object(event, x, y, flags, param): 124 | global image1, musk_image, musk_shape, drawing, mode, point1, point2, point3 125 | _image = image1.copy() 126 | (x, y) = resize_list((x, y), times) 127 | 128 | if event == cv2.EVENT_LBUTTONDOWN: 129 | point1 = (x, y) 130 | cv2.circle(_image, point1, 2, (0, 0, 255), times) 131 | cv2.imshow("find_object", resize_image(_image)) 132 | 133 | elif event == cv2.EVENT_MOUSEMOVE and (flags & cv2.EVENT_FLAG_LBUTTON): 134 | point2 = (x, y) 135 | cv2.rectangle(_image, point1, point2, (0, 0, 255), 2 * times) 136 | cv2.imshow("find_object", resize_image(_image)) 137 | 138 | elif event == cv2.EVENT_LBUTTONUP: 139 | point3 = (x, y) 140 | cv2.rectangle(_image, point1, point3, (0, 0, 255), 2 * times) 141 | cv2.imshow("find_object", resize_image(_image)) 142 | (min_x, min_y) = min(point1[0], point3[0]), min(point1[1], point3[1]) 143 | (width, height) = abs(point1[0] - point3[0]), abs(point1[1] - point3[1]) 144 | 145 | if width > 64 and height > 64: 146 | clips_image = image1[min_y: min_y + height, min_x: min_x + width] 147 | hsv = cv2.cvtColor(clips_image, cv2.COLOR_BGR2HSV) 148 | hue, saturation, value = cv2.split(hsv) 149 | retval, thresholded = cv2.threshold(saturation, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU) 150 | medianFiltered = cv2.medianBlur(thresholded, 5) 151 | _, contour_list, hierarchy = cv2.findContours(medianFiltered, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) 152 | 153 | contour_list = sorted(contour_list, key=lambda _: len(_), reverse=True) 154 | musk_image = np.zeros(clips_image.shape, np.uint8) 155 | contours_musk = cv2.drawContours(musk_image, contour_list, 0, (255, 255, 255), -1) 156 | 157 | musk_shape = musk_image.shape 158 | musk_image[contours_musk == 255] = 1 159 | musk_image = clips_image * musk_image[:, :, :] 160 | cv2.imshow("object", resize_image(musk_image)) 161 | 162 | def paste_object(event, x, y, flags, param): 163 | global image1, image2, musk_image, musk_shape, drawing, point1, point2, point3, offset_x, offset_y, flag 164 | (x, y) = resize_list((x, y), times) 165 | 166 | if x < 0 or y < 0 or x > image2.shape[1] or y > image2.shape[1]: return 167 | if event == cv2.EVENT_LBUTTONDOWN: 168 | flag = False 169 | point1 = (x, y) 170 | print("=> mouse down", (x, y)) 171 | if (x - offset_x) <= musk_shape[1] and (y - offset_y) <= musk_shape[0]: flag = True 172 | 173 | elif event == cv2.EVENT_MOUSEMOVE and (flags & cv2.EVENT_FLAG_LBUTTON): 174 | point2 = (x, y) 175 | _offset_x = offset_x + point2[0] - point1[0] 176 | _offset_y = offset_y + point2[1] - point1[1] 177 | _tmp_image = image2.copy() 178 | cv2.rectangle(_tmp_image, (_offset_x, _offset_y), (_offset_x + musk_shape[1], _offset_y + musk_shape[0]), (0, 0, 255), 2 * times) 179 | _tmp_image = get_mask_image(_tmp_image, musk_image, _offset_x, _offset_y) 180 | cv2.imshow("paste_object", resize_image(_tmp_image)) 181 | 182 | elif event == cv2.EVENT_LBUTTONUP: 183 | point3 = (x, y) 184 | print("=> mouse up", (x, y)) 185 | if flag: 186 | offset_x += point3[0] - point1[0] 187 | offset_y += point3[1] - point1[1] 188 | _tmp_image = image2.copy() 189 | cv2.rectangle(_tmp_image, (offset_x, offset_y), (offset_x + musk_shape[1], offset_y + musk_shape[0]), (0, 0, 255), 2 * times) 190 | curr_image = get_mask_image(_tmp_image, musk_image, offset_x, offset_y) 191 | cv2.imshow("paste_object", resize_image(curr_image)) 192 | flag = False 193 | 194 | class Splicing(object): 195 | def __init__(self, conf=Config): 196 | self._conf = conf 197 | self.scope_name = conf.scope_name 198 | self.input_path = self._conf.input_path 199 | self.output_path = self._conf.output_path 200 | 201 | self.model_path = os.path.join(parent_path, "model", self._conf.scope_name) 202 | self.config_path = os.path.join(self.model_path, "db.json") 203 | self.config = self.load_model_file(self.config_path) 204 | tools.rebuild(self.model_path) 205 | 206 | def save_model_file(self): 207 | print("=> {:s}() {:s}".format(sys._getframe().f_code.co_name, self.config_path)) 208 | try: 209 | with open(self.config_path, "w") as file: 210 | file.write(json.dumps(self.config)) 211 | except Exception as e: 212 | print("=> {:s}() error={:s}".format(sys._getframe().f_code.co_name, e)) 213 | 214 | def load_model_file(self, path): 215 | data = [] 216 | try: 217 | with open(path, "r+") as file: 218 | data = json.loads(file.read()) 219 | except Exception as e: 220 | print("=> {:s}() error={:s}".format(sys._getframe().f_code.co_name, e)) 221 | return data 222 | 223 | def get_next_index(self, index, offset, total_size): 224 | next_index = str((int(index) + offset) % total_size) 225 | if next_index == index: 226 | return self.get_next_index(index, offset, total_size) 227 | return next_index 228 | 229 | def saving(self, _image, path, is_ground_truth=False): 230 | cv2.imwrite(path, _image) 231 | if not is_ground_truth: 232 | self.config["splicing_list"].append(path.split("/")[-1]) 233 | print("=> add into config: {:s}".format(self.config["splicing_list"][-1])) 234 | print("=> saving splicing image={:s}".format(path)) 235 | 236 | def copy_move(self, image1_path, image2_path): 237 | global image1, image2, musk_image, offset_x, offset_y 238 | (i, j) = (0, 0) 239 | 240 | image1 = cv2.imread(image1_path) 241 | image2 = cv2.imread(image2_path) 242 | 243 | cv2.namedWindow("find_object", cv2.WINDOW_NORMAL) 244 | cv2.setMouseCallback("find_object", find_object) 245 | cv2.imshow("find_object", resize_image(image1)) 246 | cv2.imshow("paste_object", resize_image(image2)) 247 | cv2.moveWindow("paste_object", image1.shape[1] / times + 5, 0) 248 | 249 | while True: 250 | k = cv2.waitKey(0) 251 | if k in [0, 1, 2, 3, 13, ord("q")]: 252 | cv2.destroyAllWindows() 253 | 254 | if k == 0: 255 | # key = "up" 256 | i = -1 257 | return (i, j, 0, 0) 258 | elif k == 1: 259 | # key = "down" 260 | i = 1 261 | return (i, j, 0, 0) 262 | elif k == 2: 263 | # key = "left" 264 | j = -1 265 | return (i, j, 0, 0) 266 | elif k == 3: 267 | # key = "right" 268 | j = 1 269 | return (i, j, 0, 0) 270 | elif k > 48 and k < 58: 271 | return (i, j, 2, k - 49) 272 | elif k == ord("q"): 273 | exit() 274 | elif k == 13: 275 | # key = "Enter" 276 | cv2.namedWindow("paste_object", cv2.WINDOW_NORMAL) 277 | cv2.setMouseCallback("paste_object", paste_object) 278 | 279 | curr_image = get_mask_image(image2.copy(), musk_image, offset_x, offset_y) 280 | cv2.imshow("paste_object", resize_image(curr_image)) 281 | 282 | k = cv2.waitKey(0) 283 | if k in [0, 1, 2, 3, 13, ord("q")]: 284 | cv2.destroyAllWindows() 285 | 286 | if k == 0: 287 | i = -1 288 | return (i, j, 0, 0) 289 | elif k == 1: 290 | i = 1 291 | return (i, j, 0, 0) 292 | elif k == 2: 293 | j = -1 294 | return (i, j, 0, 0) 295 | elif k == 3: 296 | j = 1 297 | return (i, j, 0, 0) 298 | elif k > 48 and k < 58: 299 | return (i, j, 3, k - 49) 300 | elif k == ord("q"): 301 | exit() 302 | elif k == 13: 303 | (curr_image, truth_image) = get_mask_image(image2.copy(), musk_image, offset_x, offset_y, True) 304 | base_name = "{:s}_{:s}".format(os.path.splitext(image1_path)[0].split("/")[-1], os.path.splitext(image2_path)[0].split("/")[-1]) 305 | image_name = "{:s}_{:d}".format(base_name, int(time.time())) 306 | 307 | threading.Thread(target=self.saving, args=(curr_image, os.path.join(self.model_path, "splicing", image_name + ".bmp"), False)).start() 308 | threading.Thread(target=self.saving, args=(truth_image, os.path.join(self.model_path, "ground", image_name + ".jpg"), True)).start() 309 | return (1, 1, 1, 0) 310 | 311 | def iterator_build(self, image_list, next_image_list, subpath1, subpath2, model1, model2, cnt=0, max=100): 312 | global offset1, offset2 313 | (offset1, offset2) = (0, 0) 314 | 315 | while True: 316 | if cnt > len(image_list) or cnt > max: break 317 | image_path1 = os.path.join(subpath1, image_list[offset1]) 318 | image_path2 = os.path.join(subpath2, next_image_list[offset2]) 319 | 320 | print(image_path1, image_path2) 321 | 322 | (i, j, _, data) = self.copy_move(image_path1, image_path2) 323 | 324 | if _ == 1: 325 | if type(self.config["splicing_mark"]) is bool: 326 | self.config["splicing_mark"] = {} 327 | 328 | if not self.config["splicing_mark"].has_key("{:s}_{:s}".format(model1, model2)): 329 | self.config["splicing_mark"]["{:s}_{:s}".format(model1, model2)] = 0 330 | self.config["splicing_mark"]["{:s}_{:s}".format(model1, model2)] += 1 331 | self.save_model_file() 332 | # 信号2代表"篡改源"更换为k模型 333 | elif _ == 2: 334 | threading.Thread(target=self.run2, args=(str(data), model2)).start() 335 | break 336 | # 信号3代表"篡改目标"更换为k模型 337 | elif _ == 3: 338 | threading.Thread(target=self.run2, args=(model1, str(data))).start() 339 | break 340 | 341 | cnt += _ 342 | (offset1, offset2) = (offset1 + i + len(image_list)) % len(image_list), (offset2 + j + len(next_image_list)) % len(next_image_list) 343 | 344 | def clean(self): 345 | self.config = self.load_model_file(self.config_path) 346 | base_path = os.path.join(parent_path, "model", self._conf.scope_name) 347 | ground_list = os.listdir(os.path.join(base_path, "ground")) 348 | splicing_list = os.listdir(os.path.join(base_path, "splicing")) 349 | 350 | print("=> I find file list:\n") 351 | for item in splicing_list: 352 | print("[{:s}]".format(item)) 353 | 354 | choice = raw_input("=> Do you want to remove all? [y/n]\n") 355 | if choice.lower() == "y": 356 | print("=> removing files...") 357 | for item in splicing_list: 358 | os.unlink(os.path.join(base_path, "splicing", item)) 359 | for item in ground_list: 360 | os.unlink(os.path.join(base_path, "ground", item)) 361 | self.config["splicing_list"] = [] 362 | self.config["splicing_mark"] = False 363 | self.save_model_file() 364 | 365 | def single_read(self, splice_path, ground_path, model1=None): 366 | shape = self._conf.image_size 367 | splice = self._conf.splicing["splice"] 368 | stride = self._conf.splicing["stride"] 369 | batch_size = self._conf.batch_size 370 | 371 | splice_image = cv2.imread(splice_path) 372 | (width, height) = (splice_image.shape[1], splice_image.shape[0]) 373 | 374 | if not model1: 375 | name = ntpath.basename(ground_path) 376 | model1 = self.config["model_label"]["{:s}_{:s}".format(name.split("_")[0], name.split("_")[1])] 377 | model2 = self.config["model_label"]["{:s}_{:s}".format(name.split("_")[4], name.split("_")[5])] 378 | print("=> model1={:d} model2={:d}".format(model1, model2)) 379 | ground_image = cv2.imread(ground_path) 380 | else: 381 | name = ntpath.basename(splice_path) 382 | model2 = model1 383 | ground_image = np.ones(splice_image.shape) * 255 384 | 385 | x_max_index, y_max_index = int(width / stride - 1 + int(stride / shape[1])), int(height / stride - 1 + int(stride / shape[1])) 386 | total_crop = x_max_index * y_max_index 387 | 388 | ground_image = ground_image[:, :, 0].copy() 389 | ground_image[ground_image < 1] = 1 390 | ground_image[ground_image > 1] = 0 391 | 392 | count, X, Y, tamper_rate, offset_x, offset_y, confidence = 0, None, None, None, None, None, None 393 | flag = total_crop / batch_size if total_crop % batch_size == 0 else total_crop / batch_size + 1 394 | for index in range(total_crop): 395 | _index = index % batch_size 396 | if index > 0 and _index == 0: 397 | count += 1 398 | yield (count, flag, name.split(".")[0], X, Y, confidence, tamper_rate, splice_image.shape, offset_x, offset_y, width, height) 399 | 400 | # init value slot 401 | if _index == 0: 402 | X = np.zeros([batch_size, shape[0], shape[1], 3], dtype=np.uint8) 403 | Y = np.ones([batch_size], dtype=np.int32) * int(model2) 404 | offset_x = np.zeros([batch_size], dtype=np.int32) 405 | offset_y = np.zeros([batch_size], dtype=np.int32) 406 | tamper_rate = np.zeros([batch_size], dtype=np.float32) 407 | confidence = np.zeros([batch_size], dtype=np.float32) 408 | 409 | # get slide windows offset index and offset pixel 410 | x_index, y_index = int(index % x_max_index), int(index / x_max_index) 411 | (_offset_x, _offset_y) = (stride * (x_index), stride * (y_index)) 412 | 413 | # extract slide window image, splice rate in a slide window 414 | 415 | crop_imgage = (splice_image[_offset_y: _offset_y + shape[0], _offset_x: _offset_x + shape[1], :]).copy() 416 | crop_ground = ground_image[_offset_y: _offset_y + shape[0], _offset_x: _offset_x + shape[1]].copy() 417 | tamper_rate[_index] = float(np.sum(crop_ground) / (shape[0] * shape[1])) 418 | confidence[_index] = tools.confidence(crop_imgage) 419 | 420 | X[_index] = crop_imgage 421 | offset_x[_index] = _offset_x 422 | offset_y[_index] = _offset_y 423 | if tamper_rate[_index] > splice: Y[_index] = int(model1) 424 | 425 | # if not satisfy batch_size windows, feed last window in remaining blocks data 426 | if total_crop % batch_size != 0: 427 | for i in range(batch_size - total_crop % batch_size): 428 | _index = total_crop % batch_size + i 429 | X[_index] = X[_index - 1] 430 | Y[_index] = Y[_index - 1] 431 | tamper_rate[_index] = tamper_rate[_index - 1] 432 | offset_x[_index] = offset_x[_index - 1] 433 | offset_y[_index] = offset_y[_index - 1] 434 | confidence[_index] = confidence[_index - 1] 435 | yield (count + 1, flag, name.split(".")[0], X, Y, confidence, tamper_rate, splice_image.shape, offset_x, offset_y, width, height) 436 | 437 | def iterator(self): 438 | for item in self.config["splicing_list"]: 439 | path1 = os.path.join(self.model_path, "splicing", item) 440 | path2 = os.path.join(self.model_path, "ground", item.split(".")[0] + ".jpg") 441 | print(path1, path2) 442 | for (count, flag, name, X, Y, Q, tamper_rate, shape, offset_x, offset_y, width, height) in self.single_read(path1, path2): 443 | yield(count, flag, name, X, Y, Q, tamper_rate, shape, offset_x, offset_y, width, height) 444 | 445 | def file_iterator(self): 446 | self.config = self.load_model_file(self.config_path) 447 | 448 | for (label, files) in self.config["test_list"].items(): 449 | for name in files: 450 | name_split = name.split("_") 451 | path1 = os.path.join(self._conf.input_path, name_split[0], name_split[1], name) 452 | path2 = None 453 | 454 | for (count, flag, name, X, Y, Q, tamper_rate, shape, offset_x, offset_y, width, height) in self.single_read(path1, path2, label): 455 | yield (count, flag, name, X, Y, Q, tamper_rate, shape, offset_x, offset_y, width, height) 456 | 457 | def run(self): 458 | self.config = self.load_model_file(self.config_path) if not self.config else self.config 459 | keys = self.config["test_list"].keys() 460 | random.shuffle(keys) 461 | if not self.config.has_key("splicing_list"): self.config["splicing_list"] = [] 462 | if not self.config.has_key("splicing_mark"): self.config["splicing_mark"] = {} 463 | 464 | offset = 1 465 | for index in keys: 466 | image_list = self.config["test_list"][index] 467 | next_index = self.get_next_index(index, offset, len(self.config["label_path"])) 468 | subpath1 = os.path.join(self.input_path, self.config["label_path"][index]) 469 | subpath2 = os.path.join(self.input_path, self.config["label_path"][next_index]) 470 | self.iterator_build(image_list, self.config["test_list"][next_index], subpath1, subpath2, index, next_index) 471 | self.save_model_file() 472 | 473 | def run2(self, model1, model2, max_size=10): 474 | self.config = self.load_model_file(self.config_path) if not self.config else self.config 475 | print(str(model1), str(model2)) 476 | (model1, model2, keys) = (str(model1), str(model2), self.config["test_list"].keys()) 477 | 478 | if not model1 in keys or not model2 in keys: exit(1) 479 | if not self.config.has_key("splicing_list"): self.config["splicing_list"] = [] 480 | if not self.config.has_key("splicing_mark"): self.config["splicing_mark"] = {} 481 | 482 | image_list1 = sorted(self.config["test_list"][model1]) 483 | image_list2 = sorted(self.config["test_list"][model2]) 484 | subpath1 = os.path.join(self.input_path, self.config["label_path"][model1]) 485 | subpath2 = os.path.join(self.input_path, self.config["label_path"][model2]) 486 | self.iterator_build(image_list1, image_list2, subpath1, subpath2, model1, model2, max=max_size) 487 | self.save_model_file() 488 | 489 | if __name__ == "__main__": 490 | pass 491 | 492 | 493 | 494 | 495 | 496 | 497 | -------------------------------------------------------------------------------- /code/utils/tools.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding:utf-8 -*- 3 | 4 | __author__ = 'grasses' 5 | __email__ = 'xiaocao.grasses@gmail.com' 6 | __copyright__ = 'Copyright © 2018/08/19, grasses' 7 | 8 | import tensorflow as tf, numpy as np, math, os, errno, shutil 9 | curr_path = os.path.abspath(os.path.dirname(__file__)) 10 | parent_path = os.path.abspath(os.path.dirname(curr_path)) 11 | 12 | def to_obj(d): 13 | top = type("new", (object,), d) 14 | seqs = tuple, list, set, frozenset 15 | for i, j in d.items(): 16 | if isinstance(j, dict): 17 | setattr(top, i, to_obj(j)) 18 | elif isinstance(j, seqs): 19 | setattr(top, i, type(j)(to_obj(sj) if isinstance(sj, dict) else sj for sj in j)) 20 | else: 21 | setattr(top, i, j) 22 | return top 23 | 24 | def confidence(data): 25 | data = np.reshape(data, (-1, 3)) / 255.0 26 | mean, std = np.mean(data, axis=0), np.std(data, axis=0) 27 | Q = 0 28 | for i in range(3): 29 | Q += 0.7 * 4 * (mean[i] - mean[i] * mean[i]) 30 | Q += 0.3 * (1 - math.pow(math.e, math.log(0.01, math.e) * std[i])) 31 | Q = Q / 3.0 32 | return Q 33 | 34 | ''' 35 | clean model && board 36 | ''' 37 | def clean(base_path, scop_name): 38 | path = [os.path.join(base_path, "model", scop_name, "model"), os.path.join(base_path, "board", scop_name)] 39 | try: 40 | for item in path: 41 | for name in os.listdir(item): 42 | os.remove(os.path.join(item, name)) 43 | print("=> clean: {:s}".format(os.path.join(item, name))) 44 | except Exception as e: 45 | print(e) 46 | 47 | def backup(conf): 48 | try: 49 | shutil.copyfile(os.path.join(conf.ROOT, str(conf.__module__).split(".")[-1] + ".py"), os.path.join(conf.ROOT, "model", conf.scope_name, "model", "config")) 50 | except Exception as e: 51 | print("=> backup() e={:s}".format(str(e))) 52 | 53 | def rebuild(model_path): 54 | # common path building in initing 55 | modules = ["pre-train", "splicing", "ground", "model"] 56 | try: 57 | if not os.path.exists(model_path): 58 | os.makedirs(model_path) 59 | for item in modules: 60 | if not os.path.exists(os.path.join(model_path, item)): 61 | os.makedirs(os.path.join(model_path, item)) 62 | except OSError as e: 63 | print("=> [error] build_directory() e={:s}".format(e)) 64 | if e.errno == errno.EEXIST and os.path.isdir(model_path): 65 | pass 66 | else: 67 | raise 68 | 69 | def remove_dirty(base_path): 70 | black_list = [".DS_Store"] 71 | for name in black_list: 72 | path = "{:s}/{:s}".format(base_path, name) 73 | if os.path.isfile(path): 74 | try: 75 | os.remove(path) 76 | except Exception as e: 77 | print(e) 78 | if os.path.isdir(path): 79 | try: 80 | os.unlink(path) 81 | except Exception as e: 82 | print(e) 83 | 84 | ''' 85 | :param value tfrecords int to init64 86 | ''' 87 | def _int64_feature(value): 88 | return tf.train.Feature(int64_list=tf.train.Int64List(value=[value])) 89 | 90 | ''' 91 | :param value tfrecords int to float32 92 | ''' 93 | def _float32_feature(value): 94 | return tf.train.Feature(float_list=tf.train.FloatList(value=[value])) 95 | 96 | ''' 97 | :param value tfrecords string to byte 98 | ''' 99 | def _bytes_feature(value): 100 | return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value])) 101 | 102 | ''' 103 | normalize input X matrix value from 0~255 to -1~1 104 | :param samples numpy.array() 105 | :return samples numpy.array() 106 | ''' 107 | def normalize(samples): 108 | return samples / 128.0 - 1.0 109 | 110 | ''' 111 | reformat label Y matrix, for example: from Y=2 to Y=[0, 0, 1, 0, 0], where 1 is active value and label size is 5 112 | :param labels int 113 | :return labels numpy.array() 114 | ''' 115 | def reformat(labels, label_size): 116 | one_hot_labels = [] 117 | for num in labels: 118 | one_hot = [0.0] * label_size 119 | if num == label_size: 120 | one_hot[0] = 1.0 121 | else: 122 | one_hot[num] = 1.0 123 | one_hot_labels.append(one_hot) 124 | labels = np.array(one_hot_labels).astype(np.float32) 125 | return labels -------------------------------------------------------------------------------- /experiment/2-2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## 1.Reliability Fusion Map (RFM)\n", 8 | "\n", 9 | "
\n", 10 | "\n", 11 | "1. `matrix` is global variable from csv file
\n", 12 | " `f1, f2, f3...` is CNN confidence vector;
\n", 13 | " `p` = CNN predict label;
\n", 14 | " `y` = label of patch;
\n", 15 | " `texture_quality` = patch texture quality factor, see formula(2) in paper\n", 16 | "
\n", 17 | " \n", 18 | "2. Fusion step: `filter_texture()`->`fushion_map()`->`fusion_denisty()`;
\n", 19 | " `filter_texture()`: filter low texture patch predictions of CNN, we set threshold_texture=0;
\n", 20 | " `fushion_map()`: fusion step1, see formula(3) in paper;
\n", 21 | " `fusion_denisty()`: fusion step2, see formula(4), (5) in paper;
\n", 22 | "
\n", 23 | "\n", 24 | "3. Output matrix structure is the same as input matrix
\n", 25 | "
\n", 26 | "\n", 27 | "\n", 28 | "## 2. Step-by-Step Clustering\n", 29 | " Clustering step: `k-means` -> `filter_denisty` -> `filter_texture`\n", 30 | "
\n", 31 | " \n", 32 | "\n", 33 | "## 3.About\n", 34 | "\n", 35 | "This localization for step by step clustering algorithm proposed in [11] (see experiment 2-2 in paper).\n", 36 | "\n", 37 | "
\n", 38 | "\n", 39 | "\n", 40 | "## 4.Reference\n", 41 | "[11] L. Bondi, S. Lameri, D. Gu ̈era, P. Bestagini, E. J. Delp, and S. Tubaro, “Tampering detection and localization through clus- tering of camera-based cnn features,” in Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition Workshops, 2017, pp. 1855–1864.\n", 42 | "\n", 43 | "\n", 44 | "
\n", 45 | "\n", 46 | "> $matrix=[f1, f2, f3, f4, f5... p, y, texture_quality]" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 349, 52 | "metadata": {}, 53 | "outputs": [], 54 | "source": [ 55 | "import os, math, seaborn as sns, numpy as np, pandas as pd, matplotlib.pyplot as plt, matplotlib.image as mpimg\n", 56 | "from collections import Counter\n", 57 | "sns.set()\n", 58 | "\n", 59 | "# matrix=[f1, f2, f3, f4, f5, p, y, texture_quality]" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": 325, 65 | "metadata": {}, 66 | "outputs": [], 67 | "source": [ 68 | "root_path = \"/data/experiment\"\n", 69 | "scope_name = \"pre-train_64x64\" # The input csv is 64x64 non-overlap patches\n", 70 | "\n", 71 | "csv_root = os.path.join(root_path, scope_name)\n", 72 | "ground_root = os.path.join(root_path, \"ground\")\n", 73 | "splice_root = os.path.join(root_path, \"splicing\")" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": 276, 79 | "metadata": {}, 80 | "outputs": [], 81 | "source": [ 82 | "def kmeans(matrix, theta, label, w, h):\n", 83 | " '''\n", 84 | " k-mean clustering (see paper [11], formula (2), (3), (4))\n", 85 | " @data=[f1, f2, f3, f4, f5, p, y, quality]\n", 86 | " @theta∈[0.0, 1.0]\n", 87 | " '''\n", 88 | " # calculate index: same=(M=0), diff=(M!=0)\n", 89 | " same_index = (matrix[:, 5] == label)\n", 90 | " diff_index = (matrix[:, 5] != label)\n", 91 | " \n", 92 | " # f-mean confidence\n", 93 | " f_mean = 1.0 * np.sum(matrix[same_index, 0: 5], axis=0) / np.sum(same_index)\n", 94 | " \n", 95 | " # d(i, j) see paper [11], formula (3)\n", 96 | " tmp_data = matrix[:, 0:5].copy()\n", 97 | " tmp_data[same_index] = 0\n", 98 | " (tmp1, tmp2) = (tmp_data, tmp_data.copy())\n", 99 | " \n", 100 | " # tmp1=molecule; tmp2=denominator\n", 101 | " tmp1[diff_index] -= f_mean\n", 102 | " tmp2[diff_index] += f_mean\n", 103 | " tmp1 = np.sum(np.abs(tmp1), axis=1)\n", 104 | " tmp2 = np.sum(np.abs(tmp2), axis=1)\n", 105 | " tmp2[tmp2 == 0] = 1.0\n", 106 | " d = tmp1 / tmp2\n", 107 | " \n", 108 | " # calculate placeholder\n", 109 | " flag = (d < theta)\n", 110 | " matrix[flag, 5] = label\n", 111 | " matrix[flag, :5] = 0\n", 112 | " matrix[flag, label] = 1\n", 113 | " return matrix\n", 114 | "\n", 115 | "def filter_denisty(matrix, label, w, h): \n", 116 | " '''\n", 117 | " filter_denisty method in paper [11] Sec. 3.3 step4\n", 118 | " @matrix=[f1, f2, f3, f4, f5, p, y, texture_quality]\n", 119 | " '''\n", 120 | " flag = np.where(matrix[:, 5] != label)\n", 121 | " matrix = np.reshape(matrix, (h, w, -1))\n", 122 | " source_matrix = matrix.copy()\n", 123 | " offset = [\n", 124 | " [0, 1], [1, 0], [1, 1]\n", 125 | " ]\n", 126 | " for index in list(flag[0]):\n", 127 | " x = int(index % w)\n", 128 | " y = int(index / w)\n", 129 | " \n", 130 | " score, cnt = 0, 0\n", 131 | " for p in offset:\n", 132 | " _x = x + p[1]\n", 133 | " _y = y + p[0]\n", 134 | " \n", 135 | " # 检测是否在边界,如果不是边界要计算\n", 136 | " if (_x >= 0) and (_y >= 0) and (_x < w) and (_y < h):\n", 137 | " cnt += 1\n", 138 | " # 预测为篡改,得分+1\n", 139 | " if source_matrix[_y][_x][5] != label:\n", 140 | " score += 1\n", 141 | "\n", 142 | " # update confidence & label\n", 143 | " if score != cnt:\n", 144 | " matrix[y, x, :5] = 0\n", 145 | " matrix[y, x, label] = 1\n", 146 | " matrix[y, x, 5] = label\n", 147 | " return np.reshape(matrix, (w*h, -1))\n", 148 | "\n", 149 | "def filter_texture(matrix, label, threshold=0.4):\n", 150 | " '''\n", 151 | " Filter low texture patches, (see paper [11], formula (5))\n", 152 | " @matrix=[f1, f2, f3, f4, f5, p, y, texture_quality]\n", 153 | " '''\n", 154 | " # get placeholder\n", 155 | " flag = (matrix[:, 7] < threshold)\n", 156 | " matrix[flag, :5] = 0\n", 157 | " matrix[flag, label] = 1\n", 158 | " return matrix\n", 159 | "\n", 160 | "def local_detect_region(data, label, w, h):\n", 161 | " '''\n", 162 | " Calculate forged region coordinates\n", 163 | " @return mark_x, mark_y\n", 164 | " @param mark_x=[min_x, max_x], mark_y=[min_y, max_y]\n", 165 | " '''\n", 166 | " data = np.reshape(data, (h, w, -1))\n", 167 | " mark_x, mark_y = [w-1, 0], [h-1, 0]\n", 168 | " flag = False\n", 169 | " \n", 170 | " for j in range(h):\n", 171 | " for i in range(w):\n", 172 | " if data[j, i, 6] != label:\n", 173 | " flag = True\n", 174 | " mark_x[0] = min(mark_x[0], i)\n", 175 | " mark_x[1] = max(i, mark_x[1])\n", 176 | " mark_y[0] = min(mark_y[0], j)\n", 177 | " mark_y[1] = max(j, mark_y[1])\n", 178 | " if not flag:\n", 179 | " mark_x, mark_y = (0, w-1), (0, h-1)\n", 180 | " return mark_x, mark_y\n", 181 | "\n", 182 | "def local_accuracy(data, label, mark_x, mark_y, w, h):\n", 183 | " '''\n", 184 | " Calculate local accuracy\n", 185 | " '''\n", 186 | " area = (mark_x[1] - mark_x[0] + 1) * (mark_y[1] - mark_y[0] + 1)\n", 187 | " tmp_data = np.reshape(data, (h, w, -1))[mark_y[0]: mark_y[1], mark_x[0]: mark_x[1], 5:7].copy()\n", 188 | " tmp_data = np.reshape(tmp_data, (-1, 2))\n", 189 | "\n", 190 | " same_count = np.sum(np.equal(tmp_data[:, 0], tmp_data[:, 1]))\n", 191 | " return same_count, area\n", 192 | "\n", 193 | "def show_map(matrix, w, h, label, threshold=0):\n", 194 | " '''\n", 195 | " show hotmap\n", 196 | " @matrix=[f1, f2, f3, f4, f5, p, y]\n", 197 | " '''\n", 198 | " label_list = np.ones([w*h], dtype=np.int32) * label\n", 199 | " predict_list = matrix[0: w*h, 5]\n", 200 | " \n", 201 | " diff_matrix = np.array(np.abs(label_list - predict_list), dtype=np.bool) * 1\n", 202 | " conf_matrix = np.max(matrix[:, 0:5], axis=1)\n", 203 | " \n", 204 | " list_matrix = np.multiply(conf_matrix, diff_matrix)\n", 205 | " list_matrix[list_matrix < threshold] = 0\n", 206 | " \n", 207 | " plt.clf()\n", 208 | " f, ax = plt.subplots(figsize=(16, 10))\n", 209 | " xmap = np.reshape(list_matrix, (h, w))\n", 210 | " return sns.heatmap(xmap, linewidths=.01, cmap='YlGnBu')\n", 211 | "\n", 212 | "def show_binary(matrix, w, h):\n", 213 | " '''\n", 214 | " show binary hotmap (mask)\n", 215 | " @matrix=[f1, f2, f3, f4, f5, p, y]\n", 216 | " '''\n", 217 | " matrix = np.reshape(matrix, (h, w, -1))\n", 218 | " plt.clf()\n", 219 | " f, ax = plt.subplots(figsize=(16, 10))\n", 220 | " xmap = np.reshape(matrix[:, :, 6], (h, w)).astype(np.int32)\n", 221 | " return sns.heatmap(xmap, linewidths=.01, cmap='YlGnBu')" 222 | ] 223 | }, 224 | { 225 | "cell_type": "code", 226 | "execution_count": 346, 227 | "metadata": {}, 228 | "outputs": [ 229 | { 230 | "name": "stdout", 231 | "output_type": "stream", 232 | "text": [ 233 | "1 Sony_DSC-H50_0_47035_Agfa_Sensor505-x_0_1674_1540036585_2592_1944.csv\n", 234 | "=> cnt=0 result=0.5556, 0.9850\n", 235 | "2 Agfa_Sensor505-x_0_1633_Kodak_M1063_0_9407_1540013622_3664_2748.csv\n", 236 | "=> cnt=1 result=0.5714, 0.9962\n", 237 | "3 Kodak_M1063_0_9457_Rollei_RCP-7325XS_0_42268_1540044934_3072_2304.csv\n", 238 | "=> cnt=2 result=0.8799, 0.9890\n", 239 | "4 Kodak_M1063_0_9583_Rollei_RCP-7325XS_0_42309_1540045731_3072_2304.csv\n", 240 | "=> cnt=3 result=0.7394, 0.9826\n", 241 | "5 Kodak_M1063_0_9367_Rollei_RCP-7325XS_0_42204_1540044982_3072_2304.csv\n", 242 | "=> cnt=4 result=0.8000, 0.9977\n", 243 | "6 Sony_DSC-H50_0_47009_Rollei_RCP-7325XS_0_42216_1540044405_3072_2304.csv\n", 244 | "=> cnt=5 result=0.7971, 0.9838\n", 245 | "7 Nikon_D200_0_15026_Rollei_RCP-7325XS_0_42306_1540022925_3072_2304.csv\n", 246 | "=> cnt=6 result=0.7143, 0.9728\n", 247 | "8 Nikon_D200_0_15026_Rollei_RCP-7325XS_0_42219_1540022859_3072_2304.csv\n", 248 | "=> cnt=7 result=0.1845, 0.9242\n", 249 | "9 Rollei_RCP-7325XS_0_42267_Sony_DSC-H50_0_47004_1540033882_3456_2592.csv\n", 250 | "=> cnt=8 result=0.9426, 0.9958\n", 251 | "10 Nikon_D200_0_15026_Rollei_RCP-7325XS_0_42194_1540023187_3072_2304.csv\n", 252 | "=> cnt=9 result=0.2513, 0.9225\n", 253 | "11 Rollei_RCP-7325XS_0_42262_Sony_DSC-H50_0_46972_1540034454_3456_2592.csv\n", 254 | "=> cnt=10 result=0.9463, 0.9894\n", 255 | "12 Sony_DSC-H50_0_47031_Agfa_Sensor505-x_0_1680_1540035609_2592_1944.csv\n", 256 | "=> cnt=11 result=0.8296, 1.0000\n", 257 | "13 Agfa_Sensor505-x_0_1633_Kodak_M1063_0_9367_1540014001_3664_2748.csv\n", 258 | "=> cnt=12 result=0.6000, 0.9962\n", 259 | "14 Agfa_Sensor505-x_0_1633_Kodak_M1063_0_9409_1540016770_3664_2748.csv\n", 260 | "=> cnt=13 result=0.6000, 0.9962\n", 261 | "15 Agfa_Sensor505-x_0_1862_Kodak_M1063_0_9542_1540014306_3664_2748.csv\n", 262 | "=> cnt=14 result=0.7455, 0.9979\n", 263 | "16 Kodak_M1063_0_9583_Rollei_RCP-7325XS_0_42322_1540045771_3072_2304.csv\n", 264 | "=> cnt=15 result=0.7722, 0.9867\n", 265 | "17 Agfa_Sensor505-x_0_1667_Kodak_M1063_0_9385_1540014021_2748_3664.csv\n", 266 | "=> cnt=16 result=0.6296, 0.9954\n", 267 | "18 Kodak_M1063_0_9457_Nikon_D200_0_14908_1540041581_3872_2592.csv\n", 268 | "=> cnt=17 result=0.8160, 0.9117\n", 269 | "19 Sony_DSC-H50_0_46951_Rollei_RCP-7325XS_0_42307_1540043940_3072_2304.csv\n", 270 | "=> cnt=18 result=0.7054, 0.9873\n", 271 | "20 Agfa_Sensor505-x_0_1629_Kodak_M1063_0_9393_1540016753_3664_2748.csv\n", 272 | "=> cnt=19 result=0.9307, 0.9996\n", 273 | "21 Kodak_M1063_0_9583_Rollei_RCP-7325XS_0_42323_1540046188_3072_2304.csv\n", 274 | "=> cnt=20 result=0.7867, 0.9942\n", 275 | "22 Nikon_D200_0_15026_Kodak_M1063_0_9532_1540040503_3664_2748.csv\n", 276 | "=> cnt=21 result=0.8214, 0.9916\n", 277 | "23 Sony_DSC-H50_0_46951_Agfa_Sensor505-x_0_1627_1540037219_2592_1944.csv\n", 278 | "=> cnt=22 result=0.6889, 0.9992\n", 279 | "24 Sony_DSC-H50_0_47004_Agfa_Sensor505-x_0_1673_1540037066_2592_1944.csv\n", 280 | "=> cnt=23 result=0.5172, 0.9792\n", 281 | "25 Nikon_D200_0_15026_Kodak_M1063_0_9538_1540040290_3664_2748.csv\n", 282 | "=> cnt=24 result=0.8256, 0.9921\n", 283 | "26 Sony_DSC-H50_0_46951_Agfa_Sensor505-x_0_1629_1540037246_2592_1944.csv\n", 284 | "=> cnt=25 result=0.9171, 0.9958\n", 285 | "27 Nikon_D200_0_15026_Kodak_M1063_0_9464_1540040419_2748_3664.csv\n", 286 | "=> cnt=26 result=0.8269, 0.9887\n", 287 | "28 Nikon_D200_0_15026_Kodak_M1063_0_9532_1540040650_3664_2748.csv\n", 288 | "=> cnt=27 result=0.8000, 0.9904\n", 289 | "29 Sony_DSC-H50_0_46953_Agfa_Sensor505-x_0_1625_1540036968_2592_1944.csv\n", 290 | "=> cnt=28 result=0.8452, 0.9967\n", 291 | "30 Sony_DSC-H50_0_46953_Rollei_RCP-7325XS_0_42207_1540042602_3072_2304.csv\n", 292 | "=> cnt=29 result=0.8459, 0.9919\n", 293 | "31 Sony_DSC-H50_0_47032_Agfa_Sensor505-x_0_1673_1540036483_2592_1944.csv\n", 294 | "=> cnt=30 result=0.6731, 0.9850\n", 295 | "32 Nikon_D200_0_15026_Rollei_RCP-7325XS_0_42215_1540023061_3072_2304.csv\n", 296 | "=> cnt=31 result=0.0759, 0.8953\n", 297 | "33 Kodak_M1063_0_9457_Rollei_RCP-7325XS_0_42220_1540046000_3072_2304.csv\n", 298 | "=> cnt=32 result=0.8287, 0.9803\n", 299 | "34 Sony_DSC-H50_0_47004_Rollei_RCP-7325XS_0_42215_1540044385_3072_2304.csv\n", 300 | "=> cnt=33 result=0.7926, 0.9786\n", 301 | "35 Sony_DSC-H50_0_47031_Agfa_Sensor505-x_0_1629_1540036457_2592_1944.csv\n", 302 | "=> cnt=34 result=0.8882, 0.9775\n", 303 | "36 Nikon_D200_0_14902_Rollei_RCP-7325XS_0_42185_1540022146_3072_2304.csv\n", 304 | "=> cnt=35 result=0.7536, 0.9850\n", 305 | "37 Nikon_D200_0_15022_Rollei_RCP-7325XS_0_42203_1540022776_3072_2304.csv\n", 306 | "=> cnt=36 result=0.8647, 0.9948\n", 307 | "38 Nikon_D200_0_15026_Rollei_RCP-7325XS_0_42306_1540022339_3072_2304.csv\n", 308 | "=> cnt=37 result=0.8187, 0.9861\n", 309 | "39 Nikon_D200_0_15026_Kodak_M1063_0_9532_1540040266_3664_2748.csv\n", 310 | "=> cnt=38 result=0.7560, 0.9887\n", 311 | "40 Sony_DSC-H50_0_46998_Agfa_Sensor505-x_0_1806_1540035958_2592_1944.csv\n", 312 | "=> cnt=39 result=0.4667, 0.9467\n", 313 | "41 Kodak_M1063_0_9375_Nikon_D200_0_14908_1540019187_3872_2592.csv\n", 314 | "=> cnt=40 result=0.8744, 0.9875\n", 315 | "42 Nikon_D200_0_15026_Kodak_M1063_0_9489_1540040235_3664_2748.csv\n", 316 | "=> cnt=41 result=0.8154, 0.9908\n", 317 | "43 Nikon_D200_0_15022_Rollei_RCP-7325XS_0_42194_1540022988_3072_2304.csv\n", 318 | "=> cnt=42 result=0.5938, 0.9265\n", 319 | "44 Agfa_Sensor505-x_0_1783_Kodak_M1063_0_9468_1540016550_3664_2748.csv\n", 320 | "=> cnt=43 result=0.9566, 0.9975\n", 321 | "45 Kodak_M1063_0_9583_Rollei_RCP-7325XS_0_42220_1540046501_3072_2304.csv\n", 322 | "=> cnt=44 result=0.8061, 0.9896\n", 323 | "46 Kodak_M1063_0_9583_Rollei_RCP-7325XS_0_42204_1540046915_3072_2304.csv\n", 324 | "=> cnt=45 result=0.8121, 0.9896\n", 325 | "47 Nikon_D200_0_14902_Kodak_M1063_0_9393_1540040138_3664_2748.csv\n", 326 | "=> cnt=46 result=0.9032, 0.9900\n", 327 | "48 Sony_DSC-H50_0_47004_Agfa_Sensor505-x_0_1830_1540036334_2592_1944.csv\n", 328 | "=> cnt=47 result=0.4483, 0.9675\n", 329 | "49 Nikon_D200_0_14908_Kodak_M1063_0_9393_1540041538_3664_2748.csv\n", 330 | "=> cnt=48 result=0.9128, 0.9933\n", 331 | "50 Nikon_D200_0_15026_Rollei_RCP-7325XS_0_42218_1540022852_3072_2304.csv\n", 332 | "=> cnt=49 result=0.1378, 0.9126\n", 333 | "51 Kodak_M1063_0_9564_Nikon_D200_0_15062_1540018913_3872_2592.csv\n", 334 | "=> cnt=50 result=0.5139, 0.9900\n", 335 | "52 Agfa_Sensor505-x_0_1857_Kodak_M1063_0_9409_1540128878_3664_2748.csv\n", 336 | "=> cnt=51 result=0.7812, 0.9975\n", 337 | "53 Nikon_D200_0_15135_Rollei_RCP-7325XS_0_42262_1540023296_3072_2304.csv\n", 338 | "=> cnt=52 result=0.7800, 0.9797\n", 339 | "54 Kodak_M1063_0_9367_Rollei_RCP-7325XS_0_42203_1540044720_3072_2304.csv\n", 340 | "=> cnt=53 result=0.7778, 0.9844\n", 341 | "55 Sony_DSC-H50_0_47035_Agfa_Sensor505-x_0_1675_1540036593_2592_1944.csv\n", 342 | "=> cnt=54 result=0.6212, 0.9883\n", 343 | "56 Kodak_M1063_0_9579_Rollei_RCP-7325XS_0_42204_1540046979_3072_2304.csv\n", 344 | "=> cnt=55 result=0.8413, 0.9936\n", 345 | "57 Kodak_M1063_0_9534_Nikon_D200_0_15012_1540019588_3872_2592.csv\n", 346 | "=> cnt=56 result=0.5962, 0.9925\n", 347 | "58 Kodak_M1063_0_9555_Nikon_D200_0_15046_1540019627_3872_2592.csv\n", 348 | "=> cnt=57 result=0.6643, 0.9829\n", 349 | "59 Rollei_RCP-7325XS_0_42359_Sony_DSC-H50_0_47004_1540034825_3456_2592.csv\n", 350 | "=> cnt=58 result=0.7182, 0.9889\n", 351 | "60 Agfa_Sensor505-x_0_1811_Kodak_M1063_0_9500_1540014213_3664_2748.csv\n", 352 | "=> cnt=59 result=0.7000, 0.9992\n", 353 | "61 Kodak_M1063_0_9555_Nikon_D200_0_15038_1540018863_3872_2592.csv\n", 354 | "=> cnt=60 result=0.6500, 0.9912\n", 355 | "62 Kodak_M1063_0_9596_Rollei_RCP-7325XS_0_42314_1540046646_3072_2304.csv\n", 356 | "=> cnt=61 result=0.7333, 0.9850\n", 357 | "63 Nikon_D200_0_15026_Rollei_RCP-7325XS_0_42216_1540023068_3072_2304.csv\n", 358 | "=> cnt=62 result=0.8182, 0.9850\n", 359 | "64 Agfa_Sensor505-x_0_1633_Kodak_M1063_0_9555_1540013896_3664_2748.csv\n", 360 | "=> cnt=63 result=0.6333, 0.9971\n", 361 | "65 Rollei_RCP-7325XS_0_42208_Sony_DSC-H50_0_46910_1540034299_3456_2592.csv\n", 362 | "=> cnt=64 result=0.9176, 0.9972\n", 363 | "66 Sony_DSC-H50_0_46951_Rollei_RCP-7325XS_0_42218_1540042801_3072_2304.csv\n", 364 | "=> cnt=65 result=0.7054, 0.9878\n", 365 | "67 Sony_DSC-H50_0_46908_Agfa_Sensor505-x_0_1709_1540036840_2592_1944.csv\n", 366 | "=> cnt=66 result=0.6250, 0.9900\n", 367 | "68 Agfa_Sensor505-x_0_1858_Kodak_M1063_0_9542_1540017051_3664_2748.csv\n", 368 | "=> cnt=67 result=0.8455, 0.9937\n", 369 | "69 Rollei_RCP-7325XS_0_42337_Sony_DSC-H50_0_47030_1540028261_3456_2592.csv\n", 370 | "=> cnt=68 result=0.8542, 0.9921\n", 371 | "70 Kodak_M1063_0_9596_Rollei_RCP-7325XS_0_42203_1540046691_3072_2304.csv\n", 372 | "=> cnt=69 result=0.7879, 0.9948\n", 373 | "71 Nikon_D200_0_15026_Kodak_M1063_0_9531_1540040870_3664_2748.csv\n", 374 | "=> cnt=70 result=0.8095, 0.9908\n", 375 | "72 Sony_DSC-H50_0_46953_Agfa_Sensor505-x_0_1628_1540037231_2592_1944.csv\n", 376 | "=> cnt=71 result=0.9184, 0.9967\n", 377 | "73 Kodak_M1063_0_9457_Nikon_D200_0_14952_1540018721_3872_2592.csv\n", 378 | "=> cnt=72 result=0.1652, 0.9246\n", 379 | "74 Nikon_D200_0_15022_Kodak_M1063_0_9406_1540040371_3664_2748.csv\n", 380 | "=> cnt=73 result=0.8286, 0.9845\n", 381 | "75 Agfa_Sensor505-x_0_1633_Kodak_M1063_0_9385_1540014381_2748_3664.csv\n", 382 | "=> cnt=74 result=0.6571, 0.9975\n", 383 | "76 Nikon_D200_0_15026_Kodak_M1063_0_9529_1540040856_3664_2748.csv\n", 384 | "=> cnt=75 result=0.8359, 0.9891\n", 385 | "77 Nikon_D200_0_15026_Kodak_M1063_0_9534_1540040275_3664_2748.csv\n", 386 | "=> cnt=76 result=0.7308, 0.9850\n", 387 | "78 Kodak_M1063_0_9457_Nikon_D200_0_15008_1540019238_3872_2592.csv\n", 388 | "=> cnt=77 result=0.8000, 0.9929\n", 389 | "79 Rollei_RCP-7325XS_0_42252_Sony_DSC-H50_0_46912_1540027990_3456_2592.csv\n", 390 | "=> cnt=78 result=0.8000, 0.9907\n", 391 | "80 Rollei_RCP-7325XS_0_42337_Sony_DSC-H50_0_47021_1540034577_3456_2592.csv\n", 392 | "=> cnt=79 result=0.8444, 0.9949\n", 393 | "81 Kodak_M1063_0_9585_Nikon_D200_0_15070_1540019711_3872_2592.csv\n", 394 | "=> cnt=80 result=0.8400, 0.9908\n", 395 | "82 Kodak_M1063_0_9403_Nikon_D200_0_14908_1540017887_3872_2592.csv\n", 396 | "=> cnt=81 result=0.9358, 0.9925\n", 397 | "83 Nikon_D200_0_15022_Rollei_RCP-7325XS_0_42204_1540023016_3072_2304.csv\n", 398 | "=> cnt=82 result=0.8700, 0.9838\n", 399 | "84 Kodak_M1063_0_9557_Nikon_D200_0_15078_1540018382_3872_2592.csv\n", 400 | "=> cnt=83 result=0.0804, 0.9163\n", 401 | "85 Kodak_M1063_0_9585_Rollei_RCP-7325XS_0_42307_1540046614_3072_2304.csv\n", 402 | "=> cnt=84 result=0.8068, 0.9907\n", 403 | "86 Sony_DSC-H50_0_47027_Agfa_Sensor505-x_0_1905_1540036389_2592_1944.csv\n", 404 | "=> cnt=85 result=0.7032, 0.9792\n", 405 | "87 Kodak_M1063_0_9457_Rollei_RCP-7325XS_0_42204_1540045838_3072_2304.csv\n", 406 | "=> cnt=86 result=0.7952, 0.9838\n", 407 | "88 Kodak_M1063_0_9489_Nikon_D200_0_15012_1540106251_3872_2592.csv\n", 408 | "=> cnt=87 result=0.8042, 0.9846\n", 409 | "89 Nikon_D200_0_15026_Kodak_M1063_0_9546_1540040906_3664_2748.csv\n", 410 | "=> cnt=88 result=0.8435, 0.9942\n", 411 | "90 Kodak_M1063_0_9583_Nikon_D200_0_15056_1540019681_3872_2592.csv\n", 412 | "=> cnt=89 result=0.8205, 0.9929\n", 413 | "91 Sony_DSC-H50_0_46951_Rollei_RCP-7325XS_0_42204_1540042586_3072_2304.csv\n", 414 | "=> cnt=90 result=0.7679, 0.9902\n", 415 | "92 Kodak_M1063_0_9579_Nikon_D200_0_14908_1540130311_3872_2592.csv\n", 416 | "=> cnt=91 result=0.9370, 0.9942\n", 417 | "93 Nikon_D200_0_15026_Rollei_RCP-7325XS_0_42203_1540023000_3072_2304.csv\n", 418 | "=> cnt=92 result=0.7851, 0.9954\n", 419 | "94 Kodak_M1063_0_9457_Nikon_D200_0_14908_1540106631_3872_2592.csv\n", 420 | "=> cnt=93 result=0.9346, 0.9917\n", 421 | "95 Kodak_M1063_0_9583_Rollei_RCP-7325XS_0_42222_1540046512_3072_2304.csv\n", 422 | "=> cnt=94 result=0.7889, 0.9884\n", 423 | "96 Nikon_D200_0_14908_Kodak_M1063_0_9457_1540039923_2748_3664.csv\n", 424 | "=> cnt=95 result=0.7886, 0.9883\n", 425 | "97 Nikon_D200_0_15026_Rollei_RCP-7325XS_0_42218_1540022255_3072_2304.csv\n", 426 | "=> cnt=96 result=0.2253, 0.9271\n", 427 | "98 Agfa_Sensor505-x_0_1859_Kodak_M1063_0_9540_1540014292_3664_2748.csv\n", 428 | "=> cnt=97 result=0.6286, 0.9958\n", 429 | "99 Sony_DSC-H50_0_47027_Agfa_Sensor505-x_0_1633_1540035263_2592_1944.csv\n", 430 | "=> cnt=98 result=0.6774, 0.9758\n", 431 | "100 Nikon_D200_0_15137_Rollei_RCP-7325XS_0_42236_1540023138_3072_2304.csv\n", 432 | "=> cnt=99 result=0.8496, 0.9907\n", 433 | "101 Rollei_RCP-7325XS_0_42376_Sony_DSC-H50_0_47012_1540034877_3456_2592.csv\n", 434 | "=> cnt=100 result=0.8381, 0.9931\n", 435 | "102 Sony_DSC-H50_0_46953_Agfa_Sensor505-x_0_1628_1540107258_2592_1944.csv\n", 436 | "=> cnt=101 result=0.9013, 0.9858\n", 437 | "103 Sony_DSC-H50_0_46951_Rollei_RCP-7325XS_0_42215_1540042469_3072_2304.csv\n", 438 | "=> cnt=102 result=0.7396, 0.9907\n", 439 | "104 Rollei_RCP-7325XS_0_42376_Sony_DSC-H50_0_46949_1540023584_3456_2592.csv\n", 440 | "=> cnt=103 result=0.8684, 0.9949\n", 441 | "105 Sony_DSC-H50_0_47027_Agfa_Sensor505-x_0_1876_1540036364_2592_1944.csv\n", 442 | "=> cnt=104 result=0.7250, 0.9800\n", 443 | "106 Nikon_D200_0_15026_Kodak_M1063_0_9537_1540040284_3664_2748.csv\n", 444 | "=> cnt=105 result=0.8077, 0.9900\n", 445 | "107 Agfa_Sensor505-x_0_1826_Kodak_M1063_0_9476_1540016976_3664_2748.csv\n", 446 | "=> cnt=106 result=0.6354, 0.9916\n", 447 | "108 Agfa_Sensor505-x_0_1667_Kodak_M1063_0_9557_1540013920_3664_2748.csv\n" 448 | ] 449 | }, 450 | { 451 | "name": "stdout", 452 | "output_type": "stream", 453 | "text": [ 454 | "=> cnt=107 result=0.6481, 0.9962\n", 455 | "109 Kodak_M1063_0_9457_Rollei_RCP-7325XS_0_42218_1540045930_3072_2304.csv\n", 456 | "=> cnt=108 result=0.8571, 0.9913\n", 457 | "110 Rollei_RCP-7325XS_0_42252_Sony_DSC-H50_0_47004_1540028207_3456_2592.csv\n", 458 | "=> cnt=109 result=0.8133, 0.9944\n", 459 | "111 Kodak_M1063_0_9406_Nikon_D200_0_15008_1540018510_3872_2592.csv\n", 460 | "=> cnt=110 result=0.6667, 0.9992\n", 461 | "112 Nikon_D200_0_15026_Kodak_M1063_0_9470_1540040429_3664_2748.csv\n", 462 | "=> cnt=111 result=0.8586, 0.9908\n", 463 | "113 Nikon_D200_0_15137_Rollei_RCP-7325XS_0_42203_1540023220_3072_2304.csv\n", 464 | "=> cnt=112 result=0.8529, 0.9919\n", 465 | "114 Sony_DSC-H50_0_46912_Agfa_Sensor505-x_0_1620_1540036933_2592_1944.csv\n", 466 | "=> cnt=113 result=0.7444, 0.9817\n", 467 | "115 Agfa_Sensor505-x_0_1796_Kodak_M1063_0_9407_1540014147_3664_2748.csv\n", 468 | "=> cnt=114 result=0.4167, 0.9975\n", 469 | "116 Agfa_Sensor505-x_0_1695_Kodak_M1063_0_9385_1540014092_2748_3664.csv\n", 470 | "=> cnt=115 result=0.5000, 1.0000\n", 471 | "117 Sony_DSC-H50_0_46953_Agfa_Sensor505-x_0_1788_1540036890_2592_1944.csv\n", 472 | "=> cnt=116 result=0.8571, 0.9975\n", 473 | "118 Sony_DSC-H50_0_47447_Agfa_Sensor505-x_0_1796_1540035876_2592_1944.csv\n", 474 | "=> cnt=117 result=0.5857, 0.9825\n", 475 | "119 Sony_DSC-H50_0_47027_Rollei_RCP-7325XS_0_42208_1540042255_3072_2304.csv\n", 476 | "=> cnt=118 result=0.7083, 0.9821\n", 477 | "120 Agfa_Sensor505-x_0_1857_Kodak_M1063_0_9540_1540017019_3664_2748.csv\n", 478 | "=> cnt=119 result=0.7500, 0.9950\n", 479 | "121 Sony_DSC-H50_0_47413_Rollei_RCP-7325XS_0_42204_1540044189_3072_2304.csv\n", 480 | "=> cnt=120 result=0.7571, 0.9913\n", 481 | "122 Sony_DSC-H50_0_47027_Rollei_RCP-7325XS_0_42220_1540042288_3072_2304.csv\n", 482 | "=> cnt=121 result=0.6606, 0.9838\n", 483 | "123 Agfa_Sensor505-x_0_1783_Kodak_M1063_0_9409_1540017720_3664_2748.csv\n", 484 | "=> cnt=122 result=0.5938, 0.9967\n", 485 | "124 Rollei_RCP-7325XS_0_42337_Sony_DSC-H50_0_46927_1540023540_3456_2592.csv\n", 486 | "=> cnt=123 result=0.9018, 0.9935\n", 487 | "125 Nikon_D200_0_15026_Kodak_M1063_0_9538_1540040681_3664_2748.csv\n", 488 | "=> cnt=124 result=0.8269, 0.9900\n", 489 | "126 Rollei_RCP-7325XS_0_42337_Sony_DSC-H50_0_47009_1540034551_3456_2592.csv\n", 490 | "=> cnt=125 result=0.9241, 0.9917\n", 491 | "127 Kodak_M1063_0_9457_Rollei_RCP-7325XS_0_42220_1540044876_3072_2304.csv\n", 492 | "=> cnt=126 result=0.7500, 0.9925\n", 493 | "128 Agfa_Sensor505-x_0_1695_Kodak_M1063_0_9406_1540016503_3664_2748.csv\n", 494 | "=> cnt=127 result=0.7792, 0.9954\n", 495 | "129 Kodak_M1063_0_9457_Nikon_D200_0_15062_1540106699_3872_2592.csv\n", 496 | "=> cnt=128 result=0.8739, 0.9912\n", 497 | "130 Sony_DSC-H50_0_47035_Agfa_Sensor505-x_0_1684_1540035675_2592_1944.csv\n", 498 | "=> cnt=129 result=0.4545, 0.9825\n", 499 | "131 Nikon_D200_0_15026_Kodak_M1063_0_9531_1540040497_3664_2748.csv\n", 500 | "=> cnt=130 result=0.8000, 0.9875\n", 501 | "132 Rollei_RCP-7325XS_0_42375_Sony_DSC-H50_0_47024_1540034598_3456_2592.csv\n", 502 | "=> cnt=131 result=0.8344, 0.9921\n", 503 | "133 Nikon_D200_0_15026_Rollei_RCP-7325XS_0_42307_1540022935_3072_2304.csv\n", 504 | "=> cnt=132 result=0.3385, 0.9329\n", 505 | "134 Sony_DSC-H50_0_46953_Agfa_Sensor505-x_0_1794_1540036907_2592_1944.csv\n", 506 | "=> cnt=133 result=0.8250, 1.0000\n", 507 | "135 Sony_DSC-H50_0_47447_Rollei_RCP-7325XS_0_42214_1540042779_3072_2304.csv\n", 508 | "=> cnt=134 result=0.7013, 0.9942\n", 509 | "136 Sony_DSC-H50_0_47004_Rollei_RCP-7325XS_0_42323_1540044036_3072_2304.csv\n", 510 | "=> cnt=135 result=0.6023, 0.9439\n", 511 | "137 Agfa_Sensor505-x_0_1800_Kodak_M1063_0_9409_1540014488_3664_2748.csv\n", 512 | "=> cnt=136 result=0.6458, 0.9962\n", 513 | "138 Nikon_D200_0_15137_Rollei_RCP-7325XS_0_42267_1540023308_3072_2304.csv\n", 514 | "=> cnt=137 result=0.8700, 0.9873\n", 515 | "139 Sony_DSC-H50_0_46951_Rollei_RCP-7325XS_0_42209_1540042627_3072_2304.csv\n", 516 | "=> cnt=138 result=0.7857, 0.9907\n", 517 | "140 Rollei_RCP-7325XS_0_42250_Sony_DSC-H50_0_46970_1540033793_3456_2592.csv\n", 518 | "=> cnt=139 result=0.7654, 0.9833\n", 519 | "141 Kodak_M1063_0_9375_Nikon_D200_0_14906_1540017861_3872_2592.csv\n", 520 | "=> cnt=140 result=0.8476, 0.9825\n", 521 | "142 Nikon_D200_0_15137_Rollei_RCP-7325XS_0_42204_1540023229_3072_2304.csv\n", 522 | "=> cnt=141 result=0.8597, 0.9925\n", 523 | "143 Sony_DSC-H50_0_46951_Agfa_Sensor505-x_0_1622_1540036956_2592_1944.csv\n", 524 | "=> cnt=142 result=0.7639, 0.9867\n", 525 | "144 Nikon_D200_0_15026_Kodak_M1063_0_9540_1540040689_3664_2748.csv\n", 526 | "=> cnt=143 result=0.8137, 0.9887\n", 527 | "145 Sony_DSC-H50_0_46953_Agfa_Sensor505-x_0_1629_1540037015_2592_1944.csv\n", 528 | "=> cnt=144 result=0.9224, 0.9992\n", 529 | "146 Rollei_RCP-7325XS_0_42337_Sony_DSC-H50_0_47004_1540034541_3456_2592.csv\n", 530 | "=> cnt=145 result=0.8548, 0.9769\n", 531 | "147 Nikon_D200_0_15026_Kodak_M1063_0_9457_1540040217_2748_3664.csv\n", 532 | "=> cnt=146 result=0.8167, 0.9883\n", 533 | "148 Kodak_M1063_0_9403_Nikon_D200_0_15006_1540018496_3872_2592.csv\n", 534 | "=> cnt=147 result=0.6875, 0.9975\n", 535 | "149 Rollei_RCP-7325XS_0_42250_Sony_DSC-H50_0_46972_1540028163_3456_2592.csv\n", 536 | "=> cnt=148 result=0.9199, 0.9630\n", 537 | "150 Sony_DSC-H50_0_47027_Rollei_RCP-7325XS_0_42222_1540042297_3072_2304.csv\n", 538 | "=> cnt=149 result=0.7109, 0.9855\n", 539 | "151 Rollei_RCP-7325XS_0_42208_Sony_DSC-H50_0_46912_1540041502_3456_2592.csv\n", 540 | "=> cnt=150 result=0.7619, 0.9944\n", 541 | "152 Agfa_Sensor505-x_0_1800_Kodak_M1063_0_9470_1540016569_3664_2748.csv\n", 542 | "=> cnt=151 result=0.8694, 0.9958\n", 543 | "153 Agfa_Sensor505-x_0_1806_Kodak_M1063_0_9409_1540014174_3664_2748.csv\n", 544 | "=> cnt=152 result=0.5000, 0.9987\n", 545 | "154 Kodak_M1063_0_9367_Nikon_D200_0_14902_1540018974_3872_2592.csv\n", 546 | "=> cnt=153 result=0.0088, 0.9533\n", 547 | "155 Nikon_D200_0_15137_Rollei_RCP-7325XS_0_42222_1540023120_3072_2304.csv\n", 548 | "=> cnt=154 result=0.8449, 0.9919\n", 549 | "156 Rollei_RCP-7325XS_0_42252_Sony_DSC-H50_0_46912_1540034707_3456_2592.csv\n", 550 | "=> cnt=155 result=0.8357, 0.9903\n", 551 | "157 Kodak_M1063_0_9525_Nikon_D200_0_15046_1540018343_3872_2592.csv\n", 552 | "=> cnt=156 result=0.7870, 0.9958\n", 553 | "158 Agfa_Sensor505-x_0_1821_Kodak_M1063_0_9476_1540014540_3664_2748.csv\n", 554 | "=> cnt=157 result=0.5000, 0.9950\n", 555 | "159 Agfa_Sensor505-x_0_1783_Kodak_M1063_0_9393_1540014425_3664_2748.csv\n", 556 | "=> cnt=158 result=0.9307, 0.9996\n", 557 | "160 Sony_DSC-H50_0_46951_Rollei_RCP-7325XS_0_42215_1540042646_3072_2304.csv\n", 558 | "=> cnt=159 result=0.7667, 0.9890\n", 559 | "161 Nikon_D200_0_15137_Rollei_RCP-7325XS_0_42220_1540023260_3072_2304.csv\n", 560 | "=> cnt=160 result=0.8342, 0.9884\n", 561 | "162 Nikon_D200_0_15026_Kodak_M1063_0_9407_1540040381_3664_2748.csv\n", 562 | "=> cnt=161 result=0.8308, 0.9883\n", 563 | "163 Agfa_Sensor505-x_0_1858_Kodak_M1063_0_9559_1540017078_3664_2748.csv\n", 564 | "=> cnt=162 result=0.7532, 0.9958\n", 565 | "164 Rollei_RCP-7325XS_0_42252_Sony_DSC-H50_0_46972_1540033807_3456_2592.csv\n", 566 | "=> cnt=163 result=0.9150, 0.9681\n", 567 | "165 Kodak_M1063_0_9367_Nikon_D200_0_14902_1540019762_3872_2592.csv\n", 568 | "=> cnt=164 result=0.7619, 0.9929\n", 569 | "166 Nikon_D200_0_15026_Kodak_M1063_0_9409_1540040194_3664_2748.csv\n", 570 | "=> cnt=165 result=0.8269, 0.9887\n", 571 | "167 Nikon_D200_0_15157_Rollei_RCP-7325XS_0_42306_1540022615_3072_2304.csv\n", 572 | "=> cnt=166 result=0.7836, 0.9896\n", 573 | "168 Nikon_D200_0_15026_Kodak_M1063_0_9410_1540040201_3664_2748.csv\n", 574 | "=> cnt=167 result=0.8154, 0.9891\n", 575 | "169 Nikon_D200_0_15026_Kodak_M1063_0_9555_1540040716_3664_2748.csv\n", 576 | "=> cnt=168 result=0.8365, 0.9937\n", 577 | "170 Sony_DSC-H50_0_47027_Rollei_RCP-7325XS_0_42207_1540042248_3072_2304.csv\n", 578 | "=> cnt=169 result=0.7200, 0.9855\n", 579 | "171 Nikon_D200_0_15026_Kodak_M1063_0_9537_1540040673_3664_2748.csv\n", 580 | "=> cnt=170 result=0.7769, 0.9950\n", 581 | "172 Sony_DSC-H50_0_46953_Rollei_RCP-7325XS_0_42203_1540042176_3072_2304.csv\n", 582 | "=> cnt=171 result=0.8154, 0.9988\n", 583 | "173 Nikon_D200_0_14908_Kodak_M1063_0_9491_1540040794_3664_2748.csv\n", 584 | "=> cnt=172 result=0.9407, 0.9887\n", 585 | "174 Kodak_M1063_0_9557_Nikon_D200_0_15072_1540019350_3872_2592.csv\n", 586 | "=> cnt=173 result=0.2424, 0.9421\n", 587 | "175 Agfa_Sensor505-x_0_1820_Kodak_M1063_0_9457_1540016920_2748_3664.csv\n", 588 | "=> cnt=174 result=0.5333, 0.9962\n", 589 | "176 Sony_DSC-H50_0_46951_Rollei_RCP-7325XS_0_42306_1540043924_3072_2304.csv\n", 590 | "=> cnt=175 result=0.7524, 0.9913\n", 591 | "177 Kodak_M1063_0_9457_Rollei_RCP-7325XS_0_42218_1540044834_3072_2304.csv\n", 592 | "=> cnt=176 result=0.8182, 0.9873\n", 593 | "178 Kodak_M1063_0_9559_Rollei_RCP-7325XS_0_42208_1540046423_3072_2304.csv\n", 594 | "=> cnt=177 result=0.7475, 0.9907\n", 595 | "179 Sony_DSC-H50_0_47004_Rollei_RCP-7325XS_0_42205_1540042227_3072_2304.csv\n", 596 | "=> cnt=178 result=0.9172, 1.0000\n", 597 | "180 Rollei_RCP-7325XS_0_42376_Sony_DSC-H50_0_47027_1540034607_3456_2592.csv\n", 598 | "=> cnt=179 result=0.8325, 0.9963\n", 599 | "181 Nikon_D200_0_15050_Rollei_RCP-7325XS_0_42205_1540022818_3072_2304.csv\n", 600 | "=> cnt=180 result=0.9121, 0.9983\n", 601 | "182 Nikon_D200_0_14902_Rollei_RCP-7325XS_0_42216_1540022463_3072_2304.csv\n", 602 | "=> cnt=181 result=0.7543, 0.9861\n", 603 | "183 Sony_DSC-H50_0_47027_Agfa_Sensor505-x_0_1627_1540036071_2592_1944.csv\n", 604 | "=> cnt=182 result=0.7385, 0.9858\n", 605 | "184 Agfa_Sensor505-x_0_1857_Kodak_M1063_0_9584_1540017107_3664_2748.csv\n", 606 | "=> cnt=183 result=0.7812, 0.9954\n", 607 | "185 Nikon_D200_0_14908_Kodak_M1063_0_9406_1540038194_3664_2748.csv\n", 608 | "=> cnt=184 result=0.7800, 0.9929\n", 609 | "186 Nikon_D200_0_15026_Kodak_M1063_0_9525_1540040626_3664_2748.csv\n", 610 | "=> cnt=185 result=0.8125, 0.9871\n", 611 | "187 Sony_DSC-H50_0_46953_Rollei_RCP-7325XS_0_42220_1540042501_3072_2304.csv\n", 612 | "=> cnt=186 result=0.8167, 0.9977\n", 613 | "188 Sony_DSC-H50_0_47035_Rollei_RCP-7325XS_0_42205_1540042732_3072_2304.csv\n", 614 | "=> cnt=187 result=0.9172, 1.0000\n", 615 | "189 Agfa_Sensor505-x_0_1633_Kodak_M1063_0_9393_1540016447_3664_2748.csv\n", 616 | "=> cnt=188 result=0.9271, 0.9983\n", 617 | "190 Nikon_D200_0_15137_Rollei_RCP-7325XS_0_42218_1540023251_3072_2304.csv\n", 618 | "=> cnt=189 result=0.8611, 0.9919\n", 619 | "191 Rollei_RCP-7325XS_0_42337_Sony_DSC-H50_0_47012_1540034025_3456_2592.csv\n", 620 | "=> cnt=190 result=0.9417, 0.9907\n", 621 | "192 Nikon_D200_0_15050_Rollei_RCP-7325XS_0_42316_1540022354_3072_2304.csv\n", 622 | "=> cnt=191 result=0.7407, 0.9954\n", 623 | "193 Kodak_M1063_0_9525_Nikon_D200_0_15012_1540128765_3872_2592.csv\n", 624 | "=> cnt=192 result=0.3259, 0.8871\n", 625 | "194 Kodak_M1063_0_9367_Nikon_D200_0_14906_1540018638_3872_2592.csv\n", 626 | "=> cnt=193 result=0.6731, 0.9600\n", 627 | "195 Sony_DSC-H50_0_47408_Agfa_Sensor505-x_0_1683_1540036634_2592_1944.csv\n", 628 | "=> cnt=194 result=0.7070, 0.9483\n", 629 | "196 Agfa_Sensor505-x_0_1633_Kodak_M1063_0_9403_1540013606_3664_2748.csv\n", 630 | "=> cnt=195 result=0.6000, 0.9967\n", 631 | "197 Kodak_M1063_0_9583_Rollei_RCP-7325XS_0_42218_1540046473_3072_2304.csv\n", 632 | "=> cnt=196 result=0.8000, 0.9884\n", 633 | "198 Nikon_D200_0_15026_Kodak_M1063_0_9529_1540040489_3664_2748.csv\n", 634 | "=> cnt=197 result=0.7857, 0.9879\n", 635 | "199 Nikon_D200_0_15026_Kodak_M1063_0_9409_1540040391_3664_2748.csv\n", 636 | "=> cnt=198 result=0.8256, 0.9904\n", 637 | "200 Nikon_D200_0_15026_Rollei_RCP-7325XS_0_42222_1540022878_3072_2304.csv\n", 638 | "=> cnt=199 result=0.1889, 0.9207\n", 639 | "201 Kodak_M1063_0_9367_Nikon_D200_0_14906_1540018426_3872_2592.csv\n", 640 | "=> cnt=200 result=0.7455, 0.9592\n", 641 | "202 Nikon_D200_0_15026_Kodak_M1063_0_9531_1540040257_3664_2748.csv\n", 642 | "=> cnt=201 result=0.7714, 0.9862\n", 643 | "203 Nikon_D200_0_15026_Kodak_M1063_0_9534_1540040662_3664_2748.csv\n", 644 | "=> cnt=202 result=0.8205, 0.9916\n", 645 | "204 Sony_DSC-H50_0_47413_Rollei_RCP-7325XS_0_42273_1540043864_3072_2304.csv\n", 646 | "=> cnt=203 result=0.9124, 0.9826\n", 647 | "205 Kodak_M1063_0_9579_Rollei_RCP-7325XS_0_42204_1540046961_3072_2304.csv\n", 648 | "=> cnt=204 result=0.7765, 0.9711\n", 649 | "206 Kodak_M1063_0_9457_Nikon_D200_0_15074_1540106718_3872_2592.csv\n", 650 | "=> cnt=205 result=0.1550, 0.8829\n", 651 | "207 Sony_DSC-H50_0_47030_Agfa_Sensor505-x_0_1673_1540035299_2592_1944.csv\n", 652 | "=> cnt=206 result=0.8262, 0.9608\n", 653 | "208 Sony_DSC-H50_0_46968_Rollei_RCP-7325XS_0_42214_1540044352_3072_2304.csv\n", 654 | "=> cnt=207 result=0.5600, 0.9867\n", 655 | "209 Sony_DSC-H50_0_46953_Rollei_RCP-7325XS_0_42208_1540042608_3072_2304.csv\n", 656 | "=> cnt=208 result=0.8304, 0.9942\n", 657 | "210 Kodak_M1063_0_9559_Nikon_D200_0_15052_1540019649_3872_2592.csv\n", 658 | "=> cnt=209 result=0.6250, 0.9975\n", 659 | "211 Sony_DSC-H50_0_47447_Agfa_Sensor505-x_0_1702_1540036274_2592_1944.csv\n", 660 | "=> cnt=210 result=0.7143, 0.9867\n", 661 | "212 Kodak_M1063_0_9457_Nikon_D200_0_15008_1540018767_3872_2592.csv\n", 662 | "=> cnt=211 result=0.1270, 0.9550\n", 663 | "213 Kodak_M1063_0_9457_Nikon_D200_0_15072_1540106710_3872_2592.csv\n", 664 | "=> cnt=212 result=0.8787, 0.9908\n", 665 | "214 Agfa_Sensor505-x_0_1778_Kodak_M1063_0_9409_1540016530_3664_2748.csv\n", 666 | "=> cnt=213 result=0.6000, 1.0000\n", 667 | "215 Nikon_D200_0_15137_Rollei_RCP-7325XS_0_42236_1540023278_3072_2304.csv\n", 668 | "=> cnt=214 result=0.8534, 0.9919\n", 669 | "216 Kodak_M1063_0_9457_Rollei_RCP-7325XS_0_42215_1540045888_3072_2304.csv\n" 670 | ] 671 | }, 672 | { 673 | "name": "stdout", 674 | "output_type": "stream", 675 | "text": [ 676 | "=> cnt=215 result=0.7443, 0.9821\n", 677 | "217 Nikon_D200_0_15026_Rollei_RCP-7325XS_0_42222_1540022516_3072_2304.csv\n", 678 | "=> cnt=216 result=0.0128, 0.9161\n", 679 | "218 Kodak_M1063_0_9457_Nikon_D200_0_14984_1540106210_3872_2592.csv\n", 680 | "=> cnt=217 result=0.8615, 0.9933\n", 681 | "219 Sony_DSC-H50_0_47032_Agfa_Sensor505-x_0_1681_1540035625_2592_1944.csv\n", 682 | "=> cnt=218 result=0.8170, 0.9850\n", 683 | "220 Agfa_Sensor505-x_0_1667_Kodak_M1063_0_9409_1540013657_3664_2748.csv\n", 684 | "=> cnt=219 result=0.5758, 0.9946\n", 685 | "221 Nikon_D200_0_15026_Rollei_RCP-7325XS_0_42220_1540022267_3072_2304.csv\n", 686 | "=> cnt=220 result=0.2615, 0.9508\n", 687 | "222 Nikon_D200_0_15135_Rollei_RCP-7325XS_0_42362_1540022396_3072_2304.csv\n", 688 | "=> cnt=221 result=0.7143, 0.9797\n", 689 | "223 Kodak_M1063_0_9583_Rollei_RCP-7325XS_0_42319_1540045760_3072_2304.csv\n", 690 | "=> cnt=222 result=0.8333, 0.9936\n", 691 | "224 Rollei_RCP-7325XS_0_42337_Sony_DSC-H50_0_47012_1540034567_3456_2592.csv\n", 692 | "=> cnt=223 result=0.9348, 0.9894\n", 693 | "225 Nikon_D200_0_15026_Kodak_M1063_0_9531_1540040642_3664_2748.csv\n", 694 | "=> cnt=224 result=0.8221, 0.9916\n", 695 | "226 Nikon_D200_0_15137_Rollei_RCP-7325XS_0_42306_1540023333_3072_2304.csv\n", 696 | "=> cnt=225 result=0.8624, 0.9821\n", 697 | "227 Nikon_D200_0_15026_Rollei_RCP-7325XS_0_42220_1540022871_3072_2304.csv\n", 698 | "=> cnt=226 result=0.4405, 0.9531\n", 699 | "228 Nikon_D200_0_15026_Kodak_M1063_0_9571_1540040736_3664_2748.csv\n", 700 | "=> cnt=227 result=0.8170, 0.9912\n", 701 | "229 Kodak_M1063_0_9457_Rollei_RCP-7325XS_0_42207_1540044788_3072_2304.csv\n", 702 | "=> cnt=228 result=0.8121, 0.9867\n", 703 | "230 Kodak_M1063_0_9457_Rollei_RCP-7325XS_0_42219_1540044857_3072_2304.csv\n", 704 | "=> cnt=229 result=0.8160, 0.9821\n", 705 | "231 Sony_DSC-H50_0_46953_Rollei_RCP-7325XS_0_42314_1540043952_3072_2304.csv\n", 706 | "=> cnt=230 result=0.8532, 0.9948\n", 707 | "232 Nikon_D200_0_15026_Rollei_RCP-7325XS_0_42205_1540023030_3072_2304.csv\n", 708 | "=> cnt=231 result=0.9172, 1.0000\n", 709 | "233 Kodak_M1063_0_9559_Nikon_D200_0_15074_1540019364_3872_2592.csv\n", 710 | "=> cnt=232 result=0.7222, 0.9946\n", 711 | "234 Kodak_M1063_0_9557_Nikon_D200_0_15012_1540130220_3872_2592.csv\n", 712 | "=> cnt=233 result=0.2611, 0.8929\n", 713 | "235 Kodak_M1063_0_9555_Nikon_D200_0_15064_1540019330_3872_2592.csv\n", 714 | "=> cnt=234 result=0.2857, 0.9613\n", 715 | "236 Kodak_M1063_0_9557_Rollei_RCP-7325XS_0_42306_1540046113_3072_2304.csv\n", 716 | "=> cnt=235 result=0.7610, 0.9711\n", 717 | "237 Sony_DSC-H50_0_47027_Rollei_RCP-7325XS_0_42218_1540042271_3072_2304.csv\n", 718 | "=> cnt=236 result=0.6645, 0.9815\n", 719 | "238 Kodak_M1063_0_9457_Rollei_RCP-7325XS_0_42204_1540044752_3072_2304.csv\n", 720 | "=> cnt=237 result=0.7833, 0.9873\n", 721 | "239 Kodak_M1063_0_9457_Nikon_D200_0_14932_1540017940_3872_2592.csv\n", 722 | "=> cnt=238 result=0.8034, 0.9933\n", 723 | "240 Rollei_RCP-7325XS_0_42337_Sony_DSC-H50_0_47009_1540034014_3456_2592.csv\n", 724 | "=> cnt=239 result=0.9300, 0.9931\n", 725 | "241 Sony_DSC-H50_0_47027_Rollei_RCP-7325XS_0_42204_1540042717_3072_2304.csv\n", 726 | "=> cnt=240 result=0.6937, 0.9861\n", 727 | "242 Sony_DSC-H50_0_46951_Rollei_RCP-7325XS_0_42218_1540042485_3072_2304.csv\n", 728 | "=> cnt=241 result=0.6875, 0.9884\n", 729 | "243 Sony_DSC-H50_0_47027_Agfa_Sensor505-x_0_1629_1540035488_2592_1944.csv\n", 730 | "=> cnt=242 result=0.8697, 0.9658\n", 731 | "244 Sony_DSC-H50_0_47035_Agfa_Sensor505-x_0_1674_1540037083_2592_1944.csv\n", 732 | "=> cnt=243 result=0.5909, 0.9875\n", 733 | "245 Nikon_D200_0_15026_Kodak_M1063_0_9578_1540040928_3664_2748.csv\n", 734 | "=> cnt=244 result=0.8143, 0.9942\n", 735 | "246 Sony_DSC-H50_0_47027_Agfa_Sensor505-x_0_1674_1540035525_2592_1944.csv\n", 736 | "=> cnt=245 result=0.6797, 0.9825\n", 737 | "247 Rollei_RCP-7325XS_0_42208_Sony_DSC-H50_0_46968_1540023653_3456_2592.csv\n", 738 | "=> cnt=246 result=0.7639, 0.9935\n", 739 | "248 Agfa_Sensor505-x_0_1796_Kodak_M1063_0_9407_1540014477_3664_2748.csv\n", 740 | "=> cnt=247 result=0.6061, 0.9950\n", 741 | "249 Rollei_RCP-7325XS_0_42207_Sony_DSC-H50_0_47027_1540034204_3456_2592.csv\n", 742 | "=> cnt=248 result=0.7545, 0.9912\n", 743 | "250 Nikon_D200_0_15022_Rollei_RCP-7325XS_0_42219_1540022498_3072_2304.csv\n", 744 | "=> cnt=249 result=0.7807, 0.9763\n", 745 | "251 Kodak_M1063_0_9557_Nikon_D200_0_15046_1540018875_3872_2592.csv\n", 746 | "=> cnt=250 result=0.2314, 0.9233\n", 747 | "252 Sony_DSC-H50_0_46953_Rollei_RCP-7325XS_0_42204_1540042188_3072_2304.csv\n", 748 | "=> cnt=251 result=0.8034, 0.9971\n", 749 | "253 Kodak_M1063_0_9583_Nikon_D200_0_14902_1540130293_3872_2592.csv\n", 750 | "=> cnt=252 result=0.1012, 0.9429\n", 751 | "254 Rollei_RCP-7325XS_0_42267_Sony_DSC-H50_0_47002_1540033845_3456_2592.csv\n", 752 | "=> cnt=253 result=0.8187, 0.9935\n", 753 | "255 Agfa_Sensor505-x_0_1627_Kodak_M1063_0_9367_1540013495_3664_2748.csv\n", 754 | "=> cnt=254 result=0.3571, 0.9975\n", 755 | "256 Kodak_M1063_0_9457_Rollei_RCP-7325XS_0_42205_1540044773_3072_2304.csv\n", 756 | "=> cnt=255 result=0.9121, 0.9983\n", 757 | "257 Kodak_M1063_0_9564_Nikon_D200_0_15078_1540019372_3872_2592.csv\n", 758 | "=> cnt=256 result=0.5000, 0.9888\n", 759 | "258 Agfa_Sensor505-x_0_1859_Kodak_M1063_0_9583_1540017096_3664_2748.csv\n", 760 | "=> cnt=257 result=0.7917, 0.9950\n", 761 | "259 Nikon_D200_0_15026_Rollei_RCP-7325XS_0_42220_1540022506_3072_2304.csv\n", 762 | "=> cnt=258 result=0.0059, 0.9097\n", 763 | "260 Kodak_M1063_0_9583_Rollei_RCP-7325XS_0_42222_1540045607_3072_2304.csv\n", 764 | "=> cnt=259 result=0.8121, 0.9902\n", 765 | "261 Rollei_RCP-7325XS_0_42262_Sony_DSC-H50_0_47002_1540034480_3456_2592.csv\n", 766 | "=> cnt=260 result=0.8506, 0.9838\n", 767 | "262 Rollei_RCP-7325XS_0_42359_Sony_DSC-H50_0_46927_1540028069_3456_2592.csv\n", 768 | "=> cnt=261 result=0.7685, 0.9944\n", 769 | "263 Sony_DSC-H50_0_47027_Agfa_Sensor505-x_0_1921_1540036400_2592_1944.csv\n", 770 | "=> cnt=262 result=0.7647, 0.9733\n", 771 | "264 Kodak_M1063_0_9583_Rollei_RCP-7325XS_0_42306_1540045721_3072_2304.csv\n", 772 | "=> cnt=263 result=0.7987, 0.9902\n", 773 | "265 Rollei_RCP-7325XS_0_42262_Sony_DSC-H50_0_46972_1540034762_3456_2592.csv\n", 774 | "=> cnt=264 result=0.9403, 0.9833\n", 775 | "266 Agfa_Sensor505-x_0_1858_Kodak_M1063_0_9585_1540017113_3664_2748.csv\n", 776 | "=> cnt=265 result=0.7792, 0.9967\n", 777 | "267 Agfa_Sensor505-x_0_1857_Kodak_M1063_0_9470_1540017792_3664_2748.csv\n", 778 | "=> cnt=266 result=0.8681, 0.9958\n", 779 | "268 Sony_DSC-H50_0_47366_Agfa_Sensor505-x_0_1638_1540036204_2592_1944.csv\n", 780 | "=> cnt=267 result=0.5250, 0.9775\n", 781 | "269 Kodak_M1063_0_9473_Nikon_D200_0_14934_1540017981_3872_2592.csv\n", 782 | "=> cnt=268 result=0.5556, 0.9825\n", 783 | "270 Sony_DSC-H50_0_46951_Agfa_Sensor505-x_0_1783_1540036871_2592_1944.csv\n", 784 | "=> cnt=269 result=0.7054, 0.9842\n", 785 | "271 Rollei_RCP-7325XS_0_42364_Sony_DSC-H50_0_46946_1540028084_3456_2592.csv\n", 786 | "=> cnt=270 result=0.6545, 0.9866\n", 787 | "272 Nikon_D200_0_15026_Rollei_RCP-7325XS_0_42219_1540023093_3072_2304.csv\n", 788 | "=> cnt=271 result=0.4286, 0.9537\n", 789 | "273 Rollei_RCP-7325XS_0_42337_Sony_DSC-H50_0_47002_1540023810_3456_2592.csv\n", 790 | "=> cnt=272 result=0.8500, 0.9907\n", 791 | "274 Sony_DSC-H50_0_47027_Agfa_Sensor505-x_0_1878_1540036373_2592_1944.csv\n", 792 | "=> cnt=273 result=0.7375, 0.9767\n", 793 | "275 Sony_DSC-H50_0_46968_Agfa_Sensor505-x_0_1683_1540037187_2592_1944.csv\n", 794 | "=> cnt=274 result=0.6375, 0.9883\n", 795 | "276 Sony_DSC-H50_0_46953_Rollei_RCP-7325XS_0_42222_1540042508_3072_2304.csv\n", 796 | "=> cnt=275 result=0.7778, 1.0000\n", 797 | "277 Sony_DSC-H50_0_47447_Agfa_Sensor505-x_0_1708_1540036820_2592_1944.csv\n", 798 | "=> cnt=276 result=0.9111, 0.9942\n", 799 | "278 Agfa_Sensor505-x_0_1627_Kodak_M1063_0_9393_1540013514_3664_2748.csv\n", 800 | "=> cnt=277 result=0.9307, 0.9996\n", 801 | "279 Sony_DSC-H50_0_47027_Agfa_Sensor505-x_0_1675_1540035562_2592_1944.csv\n", 802 | "=> cnt=278 result=0.6806, 0.9733\n", 803 | "280 Kodak_M1063_0_9583_Rollei_RCP-7325XS_0_42316_1540045751_3072_2304.csv\n", 804 | "=> cnt=279 result=0.8067, 0.9890\n", 805 | "281 Nikon_D200_0_14908_Rollei_RCP-7325XS_0_42194_1540022159_3072_2304.csv\n", 806 | "=> cnt=280 result=0.7708, 0.9832\n", 807 | "282 Rollei_RCP-7325XS_0_42375_Sony_DSC-H50_0_47009_1540034857_3456_2592.csv\n", 808 | "=> cnt=281 result=0.9510, 0.9958\n", 809 | "283 Kodak_M1063_0_9489_Nikon_D200_0_14908_1540128707_3872_2592.csv\n", 810 | "=> cnt=282 result=0.8720, 0.9150\n", 811 | "284 Kodak_M1063_0_9489_Nikon_D200_0_15012_1540018801_3872_2592.csv\n", 812 | "=> cnt=283 result=0.5467, 0.9921\n", 813 | "285 Agfa_Sensor505-x_0_1702_Kodak_M1063_0_9393_1540014113_3664_2748.csv\n", 814 | "=> cnt=284 result=0.9319, 1.0000\n", 815 | "286 Sony_DSC-H50_0_46951_Rollei_RCP-7325XS_0_42204_1540042444_3072_2304.csv\n", 816 | "=> cnt=285 result=0.7232, 0.9902\n", 817 | "287 Kodak_M1063_0_9457_Nikon_D200_0_15008_1540106226_3872_2592.csv\n", 818 | "=> cnt=286 result=0.1333, 0.9321\n", 819 | "288 Kodak_M1063_0_9457_Rollei_RCP-7325XS_0_42208_1540044803_3072_2304.csv\n", 820 | "=> cnt=287 result=0.7667, 0.9821\n", 821 | "289 Kodak_M1063_0_9583_Rollei_RCP-7325XS_0_42273_1540045639_3072_2304.csv\n", 822 | "=> cnt=288 result=0.9244, 0.9902\n", 823 | "290 Sony_DSC-H50_0_46951_Rollei_RCP-7325XS_0_42205_1540042595_3072_2304.csv\n", 824 | "=> cnt=289 result=0.9000, 0.9942\n", 825 | "291 Nikon_D200_0_15026_Rollei_RCP-7325XS_0_42204_1540022792_3072_2304.csv\n", 826 | "=> cnt=290 result=0.3010, 0.9311\n", 827 | "292 Kodak_M1063_0_9457_Rollei_RCP-7325XS_0_42208_1540045861_3072_2304.csv\n", 828 | "=> cnt=291 result=0.8375, 0.9878\n", 829 | "293 Nikon_D200_0_15137_Rollei_RCP-7325XS_0_42316_1540023344_3072_2304.csv\n", 830 | "=> cnt=292 result=0.8137, 0.9913\n", 831 | "294 Kodak_M1063_0_9457_Rollei_RCP-7325XS_0_42203_1540046309_3072_2304.csv\n", 832 | "=> cnt=293 result=0.8636, 0.9948\n", 833 | "295 Rollei_RCP-7325XS_0_42376_Sony_DSC-H50_0_46951_1540023593_3456_2592.csv\n", 834 | "=> cnt=294 result=0.8485, 0.9977\n", 835 | "296 Sony_DSC-H50_0_47027_Agfa_Sensor505-x_0_1629_1540036538_2592_1944.csv\n", 836 | "=> cnt=295 result=0.8737, 0.9683\n", 837 | "297 Nikon_D200_0_15022_Rollei_RCP-7325XS_0_42218_1540023080_3072_2304.csv\n", 838 | "=> cnt=296 result=0.8667, 0.9902\n", 839 | "298 Sony_DSC-H50_0_47027_Rollei_RCP-7325XS_0_42219_1540042280_3072_2304.csv\n", 840 | "=> cnt=297 result=0.7562, 0.9902\n", 841 | "299 Nikon_D200_0_15026_Rollei_RCP-7325XS_0_42273_1540022907_3072_2304.csv\n", 842 | "=> cnt=298 result=0.8092, 0.9178\n", 843 | "300 Kodak_M1063_0_9559_Nikon_D200_0_15046_1540130260_3872_2592.csv\n", 844 | "=> cnt=299 result=0.1235, 0.9175\n", 845 | "301 Agfa_Sensor505-x_0_1695_Kodak_M1063_0_9474_1540013715_3664_2748.csv\n", 846 | "=> cnt=300 result=0.3750, 1.0000\n", 847 | "302 Rollei_RCP-7325XS_0_42252_Sony_DSC-H50_0_46996_1540023728_3456_2592.csv\n", 848 | "=> cnt=301 result=0.8222, 0.9931\n", 849 | "303 Nikon_D200_0_15026_Kodak_M1063_0_9525_1540040848_3664_2748.csv\n", 850 | "=> cnt=302 result=0.8238, 0.9921\n", 851 | "304 Nikon_D200_0_15137_Rollei_RCP-7325XS_0_42205_1540023237_3072_2304.csv\n", 852 | "=> cnt=303 result=0.8891, 0.9792\n", 853 | "305 Sony_DSC-H50_0_47009_Agfa_Sensor505-x_0_1628_1540035138_2592_1944.csv\n", 854 | "=> cnt=304 result=0.8816, 0.9733\n", 855 | "306 Nikon_D200_0_14908_Kodak_M1063_0_9407_1540038210_3664_2748.csv\n", 856 | "=> cnt=305 result=0.8199, 0.9891\n", 857 | "307 Kodak_M1063_0_9583_Rollei_RCP-7325XS_0_42219_1540046488_3072_2304.csv\n", 858 | "=> cnt=306 result=0.8000, 0.9890\n", 859 | "308 Sony_DSC-H50_0_46953_Rollei_RCP-7325XS_0_42209_1540044314_3072_2304.csv\n", 860 | "=> cnt=307 result=0.8651, 0.9948\n", 861 | "309 Nikon_D200_0_14908_Rollei_RCP-7325XS_0_42194_1540022746_3072_2304.csv\n", 862 | "=> cnt=308 result=0.8075, 0.9832\n", 863 | "310 Nikon_D200_0_15026_Kodak_M1063_0_9410_1540040401_3664_2748.csv\n", 864 | "=> cnt=309 result=0.8000, 0.9916\n", 865 | "311 Rollei_RCP-7325XS_0_42262_Sony_DSC-H50_0_46919_1540034404_3456_2592.csv\n", 866 | "=> cnt=310 result=0.8333, 0.9806\n", 867 | "312 Kodak_M1063_0_9579_Rollei_RCP-7325XS_0_42203_1540046951_3072_2304.csv\n", 868 | "=> cnt=311 result=0.7984, 0.9803\n", 869 | "313 Nikon_D200_0_15026_Rollei_RCP-7325XS_0_42236_1540022293_3072_2304.csv\n", 870 | "=> cnt=312 result=0.3314, 0.9381\n", 871 | "314 Rollei_RCP-7325XS_0_42208_Sony_DSC-H50_0_46904_1540027916_3456_2592.csv\n", 872 | "=> cnt=313 result=0.8865, 0.9954\n", 873 | "315 Rollei_RCP-7325XS_0_42376_Sony_DSC-H50_0_47024_1540034140_3456_2592.csv\n", 874 | "=> cnt=314 result=0.8250, 0.9921\n", 875 | "316 Kodak_M1063_0_9457_Rollei_RCP-7325XS_0_42222_1540044893_3072_2304.csv\n", 876 | "=> cnt=315 result=0.7576, 0.9902\n", 877 | "317 Rollei_RCP-7325XS_0_42208_Sony_DSC-H50_0_46910_1540023417_3456_2592.csv\n", 878 | "=> cnt=316 result=0.8990, 0.9912\n", 879 | "318 Nikon_D200_0_15026_Kodak_M1063_0_9516_1540040614_3664_2748.csv\n", 880 | "=> cnt=317 result=0.8286, 0.9908\n", 881 | "319 Sony_DSC-H50_0_47447_Agfa_Sensor505-x_0_1675_1540037111_2592_1944.csv\n", 882 | "=> cnt=318 result=0.7013, 0.9850\n", 883 | "320 Sony_DSC-H50_0_46908_Agfa_Sensor505-x_0_1681_1540037138_2592_1944.csv\n", 884 | "=> cnt=319 result=0.6615, 0.9925\n", 885 | "321 Rollei_RCP-7325XS_0_42252_Sony_DSC-H50_0_47012_1540028218_3456_2592.csv\n", 886 | "=> cnt=320 result=0.9417, 0.9907\n", 887 | "322 Nikon_D200_0_15137_Rollei_RCP-7325XS_0_42203_1540124910_3072_2304.csv\n", 888 | "=> cnt=321 result=0.8646, 0.9896\n", 889 | "323 Kodak_M1063_0_9583_Rollei_RCP-7325XS_0_42314_1540045741_3072_2304.csv\n", 890 | "=> cnt=322 result=0.7933, 0.9878\n", 891 | "324 Kodak_M1063_0_9579_Nikon_D200_0_14908_1540124748_3872_2592.csv\n", 892 | "=> cnt=323 result=0.7568, 0.8717\n", 893 | "325 Rollei_RCP-7325XS_0_42208_Sony_DSC-H50_0_46903_1540023403_3456_2592.csv\n" 894 | ] 895 | }, 896 | { 897 | "name": "stdout", 898 | "output_type": "stream", 899 | "text": [ 900 | "=> cnt=324 result=0.8541, 0.9889\n", 901 | "326 Kodak_M1063_0_9557_Rollei_RCP-7325XS_0_42307_1540046132_3072_2304.csv\n", 902 | "=> cnt=325 result=0.8091, 0.9792\n", 903 | "327 Sony_DSC-H50_0_46951_Rollei_RCP-7325XS_0_42207_1540044278_3072_2304.csv\n", 904 | "=> cnt=326 result=0.6875, 0.9884\n", 905 | "328 Kodak_M1063_0_9579_Nikon_D200_0_14902_1540107165_3872_2592.csv\n", 906 | "=> cnt=327 result=0.8262, 0.9867\n", 907 | "329 Kodak_M1063_0_9457_Rollei_RCP-7325XS_0_42216_1540045419_3072_2304.csv\n", 908 | "=> cnt=328 result=0.8611, 0.9907\n", 909 | "330 Nikon_D200_0_15026_Rollei_RCP-7325XS_0_42236_1540022532_3072_2304.csv\n", 910 | "=> cnt=329 result=0.1648, 0.9184\n", 911 | "331 Nikon_D200_0_14908_Kodak_M1063_0_9457_1540040775_2748_3664.csv\n", 912 | "=> cnt=330 result=0.7888, 0.9829\n", 913 | "332 Kodak_M1063_0_9583_Rollei_RCP-7325XS_0_42322_1540046173_3072_2304.csv\n", 914 | "=> cnt=331 result=0.8182, 0.9907\n", 915 | "333 Sony_DSC-H50_0_47002_Agfa_Sensor505-x_0_1627_1540035024_2592_1944.csv\n", 916 | "=> cnt=332 result=0.7097, 0.9967\n", 917 | "334 Rollei_RCP-7325XS_0_42250_Sony_DSC-H50_0_46972_1540023710_3456_2592.csv\n", 918 | "=> cnt=333 result=0.9356, 0.9787\n", 919 | "335 Agfa_Sensor505-x_0_1788_Kodak_M1063_0_9406_1540014453_3664_2748.csv\n", 920 | "=> cnt=334 result=0.6061, 0.9954\n", 921 | "336 Nikon_D200_0_14908_Kodak_M1063_0_9395_1540038181_3664_2748.csv\n", 922 | "=> cnt=335 result=0.8714, 0.9871\n", 923 | "337 Sony_DSC-H50_0_47027_Rollei_RCP-7325XS_0_42269_1540042378_3072_2304.csv\n", 924 | "=> cnt=336 result=0.9145, 0.9838\n", 925 | "338 Sony_DSC-H50_0_47035_Rollei_RCP-7325XS_0_42203_1540044126_3072_2304.csv\n", 926 | "=> cnt=337 result=0.7564, 0.9971\n", 927 | "339 Rollei_RCP-7325XS_0_42364_Sony_DSC-H50_0_47021_1540034122_3456_2592.csv\n", 928 | "=> cnt=338 result=0.8091, 0.9954\n", 929 | "340 Kodak_M1063_0_9457_Rollei_RCP-7325XS_0_42216_1540045915_3072_2304.csv\n", 930 | "=> cnt=339 result=0.7818, 0.9855\n", 931 | "341 Sony_DSC-H50_0_46954_Agfa_Sensor505-x_0_1632_1540037028_2592_1944.csv\n", 932 | "=> cnt=340 result=0.4200, 0.9425\n", 933 | "342 Sony_DSC-H50_0_47021_Agfa_Sensor505-x_0_1629_1540035230_2592_1944.csv\n", 934 | "=> cnt=341 result=0.8697, 0.9658\n", 935 | "343 Nikon_D200_0_15026_Kodak_M1063_0_9532_1540040877_3664_2748.csv\n", 936 | "=> cnt=342 result=0.8558, 0.9904\n", 937 | "344 Sony_DSC-H50_0_46951_Agfa_Sensor505-x_0_1627_1540124824_2592_1944.csv\n", 938 | "=> cnt=343 result=0.7946, 0.9942\n", 939 | "345 Agfa_Sensor505-x_0_1821_Kodak_M1063_0_9457_1540016940_2748_3664.csv\n", 940 | "=> cnt=344 result=0.7714, 0.9962\n", 941 | "346 Agfa_Sensor505-x_0_1857_Kodak_M1063_0_9407_1540130463_3664_2748.csv\n", 942 | "=> cnt=345 result=0.7604, 0.9958\n", 943 | "347 Sony_DSC-H50_0_46951_Rollei_RCP-7325XS_0_42194_1540042432_3072_2304.csv\n", 944 | "=> cnt=346 result=0.7857, 0.9936\n", 945 | "348 Sony_DSC-H50_0_46951_Rollei_RCP-7325XS_0_42216_1540042477_3072_2304.csv\n", 946 | "=> cnt=347 result=0.6875, 0.9878\n", 947 | "349 Sony_DSC-H50_0_46951_Rollei_RCP-7325XS_0_42214_1540042461_3072_2304.csv\n", 948 | "=> cnt=348 result=0.7143, 0.9890\n", 949 | "350 Sony_DSC-H50_0_46951_Rollei_RCP-7325XS_0_42214_1540042635_3072_2304.csv\n", 950 | "=> cnt=349 result=0.7292, 0.9942\n", 951 | "351 Nikon_D200_0_15022_Kodak_M1063_0_9542_1540040705_3664_2748.csv\n", 952 | "=> cnt=350 result=0.8667, 0.9825\n", 953 | "352 Sony_DSC-H50_0_47447_Rollei_RCP-7325XS_0_42205_1540044237_3072_2304.csv\n", 954 | "=> cnt=351 result=0.9172, 1.0000\n", 955 | "353 Sony_DSC-H50_0_46951_Agfa_Sensor505-x_0_1627_1540130356_2592_1944.csv\n", 956 | "=> cnt=352 result=0.8067, 0.9925\n", 957 | "354 Rollei_RCP-7325XS_0_42337_Sony_DSC-H50_0_47018_1540034061_3456_2592.csv\n", 958 | "=> cnt=353 result=0.8458, 0.9940\n", 959 | "355 Kodak_M1063_0_9490_Nikon_D200_0_14984_1540018088_3872_2592.csv\n", 960 | "=> cnt=354 result=0.7200, 1.0000\n", 961 | "356 Kodak_M1063_0_9565_Nikon_D200_0_15080_1540019393_3872_2592.csv\n", 962 | "=> cnt=355 result=0.7143, 0.9971\n", 963 | "357 Agfa_Sensor505-x_0_1783_Kodak_M1063_0_9406_1540014137_3664_2748.csv\n", 964 | "=> cnt=356 result=0.6250, 0.9996\n", 965 | "358 Rollei_RCP-7325XS_0_42376_Sony_DSC-H50_0_46946_1540023575_3456_2592.csv\n", 966 | "=> cnt=357 result=0.8278, 0.9977\n", 967 | "359 Nikon_D200_0_15026_Kodak_M1063_0_9407_1540040187_3664_2748.csv\n", 968 | "=> cnt=358 result=0.8410, 0.9916\n", 969 | "360 Sony_DSC-H50_0_46951_Rollei_RCP-7325XS_0_42240_1540042533_3072_2304.csv\n", 970 | "=> cnt=359 result=0.8224, 0.9861\n", 971 | "361 Rollei_RCP-7325XS_0_42337_Sony_DSC-H50_0_47015_1540034038_3456_2592.csv\n", 972 | "=> cnt=360 result=0.8429, 0.9944\n", 973 | "362 Kodak_M1063_0_9559_Nikon_D200_0_15056_1540018897_3872_2592.csv\n", 974 | "=> cnt=361 result=0.0357, 0.9896\n", 975 | "363 Nikon_D200_0_15026_Kodak_M1063_0_9534_1540040882_3664_2748.csv\n", 976 | "=> cnt=362 result=0.8462, 0.9937\n", 977 | "364 Nikon_D200_0_15026_Kodak_M1063_0_9543_1540040899_3664_2748.csv\n", 978 | "=> cnt=363 result=0.8857, 0.9921\n", 979 | "365 Sony_DSC-H50_0_47413_Rollei_RCP-7325XS_0_42218_1540044497_3072_2304.csv\n", 980 | "=> cnt=364 result=0.7333, 0.9809\n", 981 | "366 Nikon_D200_0_15022_Rollei_RCP-7325XS_0_42205_1540022231_3072_2304.csv\n", 982 | "=> cnt=365 result=0.8138, 0.9653\n", 983 | "367 Nikon_D200_0_15026_Kodak_M1063_0_9489_1540040445_3664_2748.csv\n", 984 | "=> cnt=366 result=0.8524, 0.9937\n", 985 | "368 Kodak_M1063_0_9457_Rollei_RCP-7325XS_0_42219_1540045947_3072_2304.csv\n", 986 | "=> cnt=367 result=0.7879, 0.9861\n", 987 | "369 Nikon_D200_0_15026_Rollei_RCP-7325XS_0_42273_1540022561_3072_2304.csv\n", 988 | "=> cnt=368 result=0.8304, 0.9311\n", 989 | "370 Sony_DSC-H50_0_46962_Agfa_Sensor505-x_0_1628_1540035423_2592_1944.csv\n", 990 | "=> cnt=369 result=0.8303, 0.9408\n", 991 | "371 Nikon_D200_0_14908_Kodak_M1063_0_9493_1540040806_3664_2748.csv\n", 992 | "=> cnt=370 result=0.8199, 0.9896\n", 993 | "372 Nikon_D200_0_15026_Kodak_M1063_0_9493_1540040464_3664_2748.csv\n", 994 | "=> cnt=371 result=0.8429, 0.9921\n", 995 | "373 Agfa_Sensor505-x_0_1620_Kodak_M1063_0_9531_1540013851_3664_2748.csv\n", 996 | "=> cnt=372 result=0.4000, 0.9979\n", 997 | "374 Agfa_Sensor505-x_0_1858_Kodak_M1063_0_9409_1540130471_3664_2748.csv\n", 998 | "=> cnt=373 result=0.8021, 0.9954\n", 999 | "375 Rollei_RCP-7325XS_0_42252_Sony_DSC-H50_0_47002_1540028195_3456_2592.csv\n", 1000 | "=> cnt=374 result=0.5062, 0.9699\n", 1001 | "376 Sony_DSC-H50_0_47027_Agfa_Sensor505-x_0_1628_1540036420_2592_1944.csv\n", 1002 | "=> cnt=375 result=0.8895, 0.9783\n", 1003 | "377 Sony_DSC-H50_0_46953_Rollei_RCP-7325XS_0_42316_1540043961_3072_2304.csv\n", 1004 | "=> cnt=376 result=0.8077, 0.9942\n", 1005 | "378 Kodak_M1063_0_9555_Rollei_RCP-7325XS_0_42220_1540045515_3072_2304.csv\n", 1006 | "=> cnt=377 result=0.7923, 0.9867\n", 1007 | "379 Sony_DSC-H50_0_46951_Rollei_RCP-7325XS_0_42208_1540044299_3072_2304.csv\n", 1008 | "=> cnt=378 result=0.6875, 0.9873\n", 1009 | "380 Rollei_RCP-7325XS_0_42376_Sony_DSC-H50_0_46962_1540023607_3456_2592.csv\n", 1010 | "=> cnt=379 result=0.9473, 0.9991\n", 1011 | "381 Sony_DSC-H50_0_46951_Rollei_RCP-7325XS_0_42205_1540042451_3072_2304.csv\n", 1012 | "=> cnt=380 result=0.8931, 0.9919\n", 1013 | "382 Rollei_RCP-7325XS_0_42252_Sony_DSC-H50_0_46996_1540028177_3456_2592.csv\n", 1014 | "=> cnt=381 result=0.8523, 0.9935\n", 1015 | "383 Agfa_Sensor505-x_0_1859_Kodak_M1063_0_9555_1540017061_3664_2748.csv\n", 1016 | "=> cnt=382 result=0.7614, 0.9967\n", 1017 | "384 Sony_DSC-H50_0_47035_Rollei_RCP-7325XS_0_42276_1540042395_3072_2304.csv\n", 1018 | "=> cnt=383 result=0.9052, 0.9948\n", 1019 | "385 Agfa_Sensor505-x_0_1633_Kodak_M1063_0_9407_1540013637_3664_2748.csv\n", 1020 | "=> cnt=384 result=0.6571, 0.9967\n", 1021 | "386 Kodak_M1063_0_9557_Rollei_RCP-7325XS_0_42207_1540046408_3072_2304.csv\n", 1022 | "=> cnt=385 result=0.7773, 0.9861\n", 1023 | "387 Kodak_M1063_0_9559_Rollei_RCP-7325XS_0_42216_1540046441_3072_2304.csv\n", 1024 | "=> cnt=386 result=0.7273, 0.9890\n", 1025 | "388 Rollei_RCP-7325XS_0_42252_Sony_DSC-H50_0_46910_1540027974_3456_2592.csv\n", 1026 | "=> cnt=387 result=0.7811, 0.9773\n", 1027 | "389 Agfa_Sensor505-x_0_1811_Kodak_M1063_0_9471_1540014512_3664_2748.csv\n", 1028 | "=> cnt=388 result=0.9084, 0.9992\n", 1029 | "390 Nikon_D200_0_15026_Rollei_RCP-7325XS_0_42273_1540022323_3072_2304.csv\n", 1030 | "=> cnt=389 result=0.8931, 0.9705\n", 1031 | "391 Rollei_RCP-7325XS_0_42252_Sony_DSC-H50_0_46912_1540034388_3456_2592.csv\n", 1032 | "=> cnt=390 result=0.8067, 0.9898\n", 1033 | "392 Kodak_M1063_0_9457_Rollei_RCP-7325XS_0_42215_1540044821_3072_2304.csv\n", 1034 | "=> cnt=391 result=0.7955, 0.9815\n", 1035 | "393 Kodak_M1063_0_9523_Nikon_D200_0_15012_1540128751_3872_2592.csv\n", 1036 | "=> cnt=392 result=0.2893, 0.9242\n", 1037 | "394 Kodak_M1063_0_9584_Rollei_RCP-7325XS_0_42306_1540046593_3072_2304.csv\n", 1038 | "=> cnt=393 result=0.8166, 0.9907\n", 1039 | "395 Agfa_Sensor505-x_0_1811_Kodak_M1063_0_9529_1540014253_3664_2748.csv\n", 1040 | "=> cnt=394 result=0.6667, 0.9975\n", 1041 | "396 Nikon_D200_0_14902_Kodak_M1063_0_9393_1540038166_3664_2748.csv\n", 1042 | "=> cnt=395 result=0.9271, 0.9983\n", 1043 | "397 Sony_DSC-H50_0_46951_Rollei_RCP-7325XS_0_42236_1540042526_3072_2304.csv\n", 1044 | "=> cnt=396 result=0.6786, 0.9861\n", 1045 | "398 Sony_DSC-H50_0_46953_Rollei_RCP-7325XS_0_42320_1540043976_3072_2304.csv\n", 1046 | "=> cnt=397 result=0.8482, 0.9936\n", 1047 | "399 Kodak_M1063_0_9579_Rollei_RCP-7325XS_0_42204_1540046936_3072_2304.csv\n", 1048 | "=> cnt=398 result=0.7849, 0.9757\n", 1049 | "400 Kodak_M1063_0_9579_Nikon_D200_0_14934_1540124764_3872_2592.csv\n", 1050 | "=> cnt=399 result=0.0658, 0.8829\n" 1051 | ] 1052 | } 1053 | ], 1054 | "source": [ 1055 | "# Local & global accuracy of localization\n", 1056 | "\n", 1057 | "def get_label(name):\n", 1058 | " name_label = {\n", 1059 | " \"Agfa\": 0,\n", 1060 | " \"Kodak\": 1,\n", 1061 | " \"Nikon\": 2,\n", 1062 | " \"Rollei\": 3,\n", 1063 | " \"Sony\": 4\n", 1064 | " }\n", 1065 | " name_list = name.split(\"_\")\n", 1066 | " return (name_label[name_list[0]], name_label[name_list[4]]) \n", 1067 | "\n", 1068 | "cnt, score, threshold_1, threshold_2 = 0, 0, 0.7, 0.0\n", 1069 | "result = np.zeros([len(os.listdir(csv_root)), 4])\n", 1070 | "\n", 1071 | "for name in os.listdir(csv_root):\n", 1072 | " print(cnt + 1, name)\n", 1073 | " \n", 1074 | " (_w, _h) = (int(int(name.split(\"_\")[-2])), int(int(name.split(\"_\")[-1].split(\".\")[-2])))\n", 1075 | " (w, h) = int(_w / 64), int(_h / 64)\n", 1076 | " \n", 1077 | " # @raw_data=[f1, f2, f3, f4, f5, p, y, texture]\n", 1078 | " raw_data = pd.read_csv(csv_root + \"/\" + name).values[:w*h, 1:9]\n", 1079 | " \n", 1080 | " # get label\n", 1081 | " label1, label2 = get_label(name)\n", 1082 | " \n", 1083 | " # f-L1 clustering1\n", 1084 | " f_data = kmeans(raw_data, threshold_1, label2, w, h)\n", 1085 | " # texture clustering2\n", 1086 | " t_data = filter_texture(f_data, label2, threshold_2)\n", 1087 | " # denisty clustering3\n", 1088 | " d_data = filter_denisty(t_data, label2, w, h)\n", 1089 | " \n", 1090 | " d_data[d_data[:, 5] != label2] = label1\n", 1091 | " \n", 1092 | " # final map\n", 1093 | " show_binary(raw_data, w, h)\n", 1094 | " \n", 1095 | " full_count = np.sum(np.equal(d_data[:, 5], t_data[:, 6]))\n", 1096 | " full_area = w*h\n", 1097 | " \n", 1098 | " mark_x, mark_y = local_detect_region(d_data, label2, w, h)\n", 1099 | " (local_count, local_area) = local_accuracy(d_data, label2, mark_x, mark_y, w, h)\n", 1100 | " \n", 1101 | " result[cnt, :] = np.array(list([local_count, float(local_count/local_area), full_count, float(full_count/full_area)]))\n", 1102 | " print(\"=> cnt={:d} result={:.4f}, {:.4f}\".format(cnt, result[cnt, 1], result[cnt, 3]))\n", 1103 | " \n", 1104 | " cnt += 1" 1105 | ] 1106 | }, 1107 | { 1108 | "cell_type": "code", 1109 | "execution_count": 347, 1110 | "metadata": {}, 1111 | "outputs": [ 1112 | { 1113 | "data": { 1114 | "text/plain": [ 1115 | "0.733743428382813" 1116 | ] 1117 | }, 1118 | "execution_count": 347, 1119 | "metadata": {}, 1120 | "output_type": "execute_result" 1121 | } 1122 | ], 1123 | "source": [ 1124 | "np.sum(result[:, 1]) / 400" 1125 | ] 1126 | }, 1127 | { 1128 | "cell_type": "code", 1129 | "execution_count": 348, 1130 | "metadata": {}, 1131 | "outputs": [ 1132 | { 1133 | "data": { 1134 | "text/plain": [ 1135 | "0.9829811912593985" 1136 | ] 1137 | }, 1138 | "execution_count": 348, 1139 | "metadata": {}, 1140 | "output_type": "execute_result" 1141 | } 1142 | ], 1143 | "source": [ 1144 | "np.sum(result[:, 3]) / 400" 1145 | ] 1146 | }, 1147 | { 1148 | "cell_type": "code", 1149 | "execution_count": null, 1150 | "metadata": {}, 1151 | "outputs": [], 1152 | "source": [] 1153 | } 1154 | ], 1155 | "metadata": { 1156 | "kernelspec": { 1157 | "display_name": "Python 3", 1158 | "language": "python", 1159 | "name": "python3" 1160 | }, 1161 | "language_info": { 1162 | "codemirror_mode": { 1163 | "name": "ipython", 1164 | "version": 3 1165 | }, 1166 | "file_extension": ".py", 1167 | "mimetype": "text/x-python", 1168 | "name": "python", 1169 | "nbconvert_exporter": "python", 1170 | "pygments_lexer": "ipython3", 1171 | "version": "3.5.2" 1172 | } 1173 | }, 1174 | "nbformat": 4, 1175 | "nbformat_minor": 2 1176 | } 1177 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding:utf-8 -*- 3 | # 4 | # ___====-_ _-====___ 5 | # _--^^^#####// \\#####^^^--_ 6 | # _-^##########// ( ) \\##########^-_ 7 | # -############// |\^^/| \\############- 8 | # _/############// (@::@) \\############\_ 9 | # /#############(( \\// ))#############\ 10 | # -###############\\ (oo) //###############- 11 | # -#################\\ / VV \ //#################- 12 | # -###################\\/ \//###################- 13 | # _#/|##########/\######( /\ )######/\##########|\#_ 14 | # |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \| 15 | # ` |/ V V ` V \#\| | | |/#/ V ' V V \| ' 16 | # ` ` ` ` / | | | | \ ' ' ' ' 17 | # ( | | | | ) 18 | # __\ | | | | /__ 19 | # (vvv(VVV)(VVV)vvv) 20 | # 21 | # God bless me, no bug! 22 | # `=---=' 23 | # 24 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 25 | # 26 | __author__ = 'grasses' 27 | __email__ = 'xiaocao.grasses@gmail.com' 28 | __copyright__ = 'Copyright © 2018/08/20, grasses' 29 | 30 | import argparse, os 31 | curr_dir = os.path.abspath(os.path.dirname(__file__)) 32 | 33 | def get_arguments(): 34 | parser = argparse.ArgumentParser(description="Forged Image Detection and Localization with Tensorflow script") 35 | parser.add_argument("--action", type=str, default="splicing", choices=("generator", "splicing", "train", "test", "download", "clean", "board"), help="Target action") 36 | parser.add_argument("--conf", type=str, default="code.config", help="Load config file: `code.config` as an example") 37 | 38 | # only for splicing 39 | parser.add_argument("--source_model", type=str, default="0", help="Splicing source image model id") 40 | parser.add_argument("--target_model", type=str, default="1", help="Splicing object image model id") 41 | 42 | # only for generator 43 | parser.add_argument("--run", type=str, default="write", help="Write tfrecord") 44 | 45 | # only for tensorboard 46 | parser.add_argument("--port", type=int, default=6006, help="Tensorboard port") 47 | 48 | # only for tamper 49 | parser.add_argument("--type", type=str, default="forged", choices=("forged", "true"), help="Project type") 50 | 51 | # only for download 52 | parser.add_argument("--name", type=str, default="Dresden", choices=("Dresden",), help="Database name") 53 | return parser.parse_args() 54 | 55 | def main(): 56 | args = get_arguments() 57 | conf = __import__(args.conf, globals(), locals(), ["Config"]).Config 58 | 59 | if args.action == "splicing": 60 | '''tampering image with opencv''' 61 | from code.utils import Splicing 62 | S = Splicing(conf) 63 | S.clean() 64 | S.run2(args.source_model, args.target_model) 65 | 66 | elif args.action == "generator": 67 | '''build tfrecords''' 68 | from code.utils import Generator 69 | G = Generator(conf, debug=True) 70 | G.write() 71 | 72 | elif args.action == "train": 73 | '''setup training pipeline''' 74 | from code.train import main 75 | main(conf) 76 | 77 | elif args.action == "test": 78 | from code.test import Test 79 | from code.utils import Splicing 80 | from code.network import Network 81 | S = Splicing(conf=conf) 82 | T = Test(net=Network(conf=conf)) 83 | 84 | if args.type == "forged": 85 | '''test forged images''' 86 | T.run(S.iterator) 87 | elif args.type == "true": 88 | '''test no forged images''' 89 | T.run(S.file_iterator, is_true_test=True) 90 | 91 | elif args.action == "clean": 92 | '''clean saved tensorflow model''' 93 | from code.utils import tools 94 | check = raw_input("Do you want to clean: {:s}? [Y/N]\n".format(conf.scope_name)) 95 | if check.lower() == "y": 96 | tools.clean(os.path.join(curr_dir, "code"), conf.scope_name) 97 | print("=> Clean!") 98 | 99 | elif args.action == "board": 100 | '''run tensorboard''' 101 | import subprocess 102 | path = os.path.join(curr_dir, "code", "board") 103 | port = args.port 104 | p = subprocess.Popen( 105 | ["tensorboard", "--port="+str(port), "--logdir="+str(path)], 106 | stdout=subprocess.PIPE, 107 | stdin=subprocess.PIPE 108 | ) 109 | p.stdout.read() 110 | 111 | elif args.action == "download": 112 | '''download dataset''' 113 | from code.utils.download import Download 114 | D = Download(conf, args.name) 115 | D.run(debug=True) 116 | 117 | if __name__ == "__main__": 118 | main() -------------------------------------------------------------------------------- /paper_RFM.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grasses/Tampering-Detection-and-Localization/96f2c1f8d13f375bbd11f915d24650cacc474500/paper_RFM.pdf -------------------------------------------------------------------------------- /static/result-2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grasses/Tampering-Detection-and-Localization/96f2c1f8d13f375bbd11f915d24650cacc474500/static/result-2.jpg -------------------------------------------------------------------------------- /static/result-3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grasses/Tampering-Detection-and-Localization/96f2c1f8d13f375bbd11f915d24650cacc474500/static/result-3.jpg --------------------------------------------------------------------------------