项目作者: wkdhkr

项目描述 :
import various files, detect duplicates with sqlite, reject image file by deep learning.
高级语言: JavaScript
项目地址: git://github.com/wkdhkr/dedupper.git
创建时间: 2018-03-03T11:45:53Z
项目社区:https://github.com/wkdhkr/dedupper

开源协议:MIT License

下载


logo

Windows build status
codecov
Maintainability Greenkeeper badge

Importing a lot of files while eliminating duplication. Currently, this application focuses on image files. Even video files can be used as it is (file hash only).

Dedupper uses the current time date for the file path. You do not have to worry about flooding files in one directory.

Key features

  • duplicated image detection(pHash, dHash, imageMagick signature)
  • SQLite integration(Even if you delete a file, the hash will not be lost from SQLite DB.)
  • Dedupper has the ability to repair consistency of SQLite DB when moving or deleting registered files.
  • Examine files that are suspected of duplication.
  • nsfw image filtering by Open nsfw model
  • face of gender/age image filtering by rude-carnie
  • suggest same image of higher quality

How it works

  1. Gather information on files. (Resolution, hash value, file size, etc.)
  2. Check if there is anything already gotten. To eliminate duplication.
  3. Duplicate suspected files are compared and judged in detail.
  4. In addition, machine learning can also reject images that do not meet the criteria.
  5. No problem new files will be imported, delete duplicate files or leave the final decision to the user.
  6. Files judged to be better may be replaced with existing files.

Setup

Dedupper

  • only support Windows 10 x64.
  1. choco install imagemagick --version 7.0.7.6 -y
  2. choco install ffmpeg --version 3.4.2 -y
  3. npm install --global --production windows-build-tools
  4. git clone https://github.com/wkdhkr/dedupper.git
  5. cd dedupper
  6. npm install
  7. npm run build
  8. npm link

Deep learning

Cuda, cuDNN

If you use tensorflow-gpu, following is required. good performance more than cpu.

Python 3

install miniconda for setup tensorflow etc.

  • choco install miniconda3 -y

You can choose either tensorflow or tensorflow-cpu.(recommend: tensorflow. use gpu.)

NOTE: activate command is not work in Powershell. try conda install -n root -c pscondaenvs pscondaenvs.

NOTE: Just install miniconda when using yaml file. pip/conda install is not needed.

manual install version.

  • Miniconda with Python 3.6
    • Tensorflow 1.5(GPU)
      • conda create -n tensorflow python=3.6 anaconda
      • acvitate tensorflow
      • pip install tensorflow-gpu
    • Tensorflow 1.5(CPU)
      • conda create -n tensorflow-cpu python=3.6 anaconda
      • acvitate tensorflow-cpu
      • pip install tensorflow
    • OpenCV(in activated environment)
      • conda install -c anaconda html5lib
        • prevent opencv installation issue.
      • pip install opencv-python
    • dlib(in activated environment)
      • conda install -c conda-forge dlib=19.4

yaml install version.

  1. conda env create -f tensorflow-cpu.yaml
  2. conda env create -f tensorflow.yaml

ruda-carnie, open_nsfw

use cmder for this setup. you can install it by choco install cmder -y.

first, setup rude-carnie.

  1. cd
  2. mkdir src
  3. cd src
  4. git clone https://github.com/wkdhkr/rude-carnie.git`
  5. cd rude-carnie
  6. wget http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2
  7. bunzip2 shape_predictor_68_face_landmarks.dat.bz2

setup checkpoints folder.

  1. checkpoints/
  2. ├── age
  3. └── inception
  4. └── 22801
  5. ├── checkpoint
  6. ├── checkpoint-14999.data-00000-of-00001
  7. ├── checkpoint-14999.index
  8. └── checkpoint-14999.meta
  9. └── gender
  10. └── inception
  11. └── 21936
  12. ├── checkpoint
  13. ├── checkpoint-14999.data-00000-of-00001
  14. ├── checkpoint-14999.index
  15. └── checkpoint-14999.meta

next, setup open_nsfw.

  1. cd
  2. cd src
  3. git clone https://github.com/wkdhkr/tensorflow-open_nsfw.git

that it! start following ps1 script files.

Explorer Context Menu

Run install.bat to install explorer right click menu.
If uninstalling, run uninstall.bat.

CLI

  1. $ dedupper -h
  2. Usage: dedupper [options]
  3. Options:
  4. -x --db-repair repair db by log file.
  5. -C, --no-cache no use file info cache
  6. -m, --manual the current path is registered in the destination.
  7. -k, --keep save the file as keeping state
  8. -r, --relocate relocate saved file
  9. -D, --no-dir-keep no use old dir path for new path
  10. -R, --no-report disable report output
  11. -v, --verbose show debug log
  12. -q, --quiet no prompt window
  13. -w, --wait wait on process end
  14. -l, --log-level [level] log level
  15. -L, --no-log-config no log config
  16. -P, --no-p-hash skip p-hash matching
  17. -p, --path [path] target file path
  18. -n, --dryrun dryrun mode
  19. -h, --help output usage information

Configuration

You can customize dedupper’s behavior by creating ~/.dedupper.config.js.

Refer to the source code comment for a description of config. see this.

Default config is this.

Example Config

  1. const path = require("path");
  2. const { defaultConfig } = require(process.env.USERPROFILE +
  3. "\\AppData\\Roaming\\npm\\node_modules\\dedupper");
  4. const deepLearningApiConfig = {
  5. nsfwApi: "http://localhost:5000/image",
  6. faceDetectWithGenderApi: "http://localhost:5001/face/detect",
  7. facePredictAgeApi: "http://localhost:5002/face/predict"
  8. };
  9. const deepLearningConfig = {
  10. ...deepLearningApiConfig,
  11. instantDelete: false,
  12. logicalOperation: "or",
  13. nsfwType: "sfw",
  14. nsfwMode: "allow",
  15. // nsfwMode: "none",
  16. nsfwThreshold: 0.1,
  17. faceCategories: [
  18. ["F", "(0, 2)"],
  19. ["F", "(4, 6)"],
  20. ["F", "(8, 12)"],
  21. ["F", "(15, 20)"],
  22. ["F", "(25, 32)"],
  23. ["F", "(38, 43)"],
  24. ["F", "(48, 53)"]
  25. ],
  26. faceMode: "allow",
  27. // faceMode: "none",
  28. faceMinLongSide: 300
  29. };
  30. const userConfig = {
  31. archiveExtract: true,
  32. archiveExtractCommand:
  33. '"C:\\Program Files (x86)\\LhaForge\\LhaForge.exe" "/cfg:C:\\Program Files (x86)\\LhaForge\\LhaForge.ini" /e',
  34. // libraryPathHourOffset: 24,
  35. // libraryPathDate: new Date("2018-03-17"),
  36. baseLibraryPathByType: {
  37. ["TYPE_IMAGE"]: "B:\\Image",
  38. ["TYPE_VIDEO"]: "B:\\Video"
  39. },
  40. forceConfig: {
  41. pHash: false,
  42. keep: true
  43. },
  44. deepLearningConfig,
  45. pathMatchConfig: {
  46. [path.join(process.env.USERPROFILE, "Downloads\\")]: {
  47. maxWorkers: 1,
  48. pHashIgnoreSameDir: false,
  49. keep: false
  50. }
  51. },
  52. classifyTypeConfig: {
  53. TYPE_VIDEO: {
  54. keep: false, // Override pathMatchConfig,
  55. useFileName: true
  56. }
  57. },
  58. // dbBasePath: path.join(process.env.USERPROFILE, ".dedupper/db_test"),
  59. logLevel: "trace",
  60. renameRules: [
  61. // iv code
  62. p => {
  63. const parsedPath = path.parse(p);
  64. const dirName = path.basename(parsedPath.dir);
  65. const match = dirName.match(/^\[(.*?)\]/);
  66. if (match && match[1]) {
  67. const codeName = match[1];
  68. if (codeName === parsedPath.name) {
  69. return parsedPath.dir + parsedPath.ext;
  70. }
  71. }
  72. return p;
  73. },
  74. [/\\photo\\/i, "\\"],
  75. [/.(mp4|wmv|mkv|png|jpg).(mp4|wmv|mkv|png|jpg)/, ".$1"],
  76. ["src\\dedupper\\", "\\"],
  77. [/\\[\s ]+/g, "\\"],
  78. [/[\s ]+\\/g, "\\"],
  79. [/\\download(s|)\\/gi, "\\"],
  80. [/\\images\\/gi, "\\"],
  81. [/\\refs\\/gi, "\\"],
  82. [/\\root\\/gi, "\\"],
  83. [/\\new folder[^\\]*\\/g, "\\"],
  84. [/新しいフォルダ(ー|)( \([0-9]+\)|)/g, ""],
  85. [/( - copy)+\\/gi, "\\"],
  86. [/\\\#[0-9]+\\/i, "\\"],
  87. [
  88. new RegExp(
  89. `${["\\\\Users", process.env.USERNAME].join("\\\\")}\\\\`,
  90. "i"
  91. ),
  92. "\\"
  93. ]
  94. ],
  95. ngFileNamePatterns: [
  96. ".picasa.ini",
  97. /_cropped\.(jpg|png)/i,
  98. ".DS_store",
  99. "Thumbs.db",
  100. ".BridgeSort"
  101. ],
  102. ngDirPathPatterns: [/\\backup\\/i],
  103. classifyTypeByExtension: defaultConfig.classifyTypeByExtension
  104. };
  105. userConfig.classifyTypeByExtension["txt"] = "TYPE_SCRAP";
  106. module.exports = userConfig;

How to use

  • From the menu that appears by right-clicking on a file or folder in Windows Explorer.
  • CLI.

Dedupper can handle both files and folders. The processing object itself is a file. Empty folders will be deleted.

Glossary

Action Type

“Action Type” shows how to process the file. For example, save, erase, replace, or ignore.

see this.

Reason Type

“Reason Type” is the reason why each file became “Action” of each.

see this.

Classify Type

“Classify Types” is assigned one for each file extension type and can be controlled individually as to how it is processed.

see this.

File State

“File State” is the state of the file. There are deduplicated state, accepted state, keep state, and so on.

see this.

Examination phase

When there is no confidence of the threshold with the image judged as the same image, Dedupper leaves the judgment to the user.

The duplicate candidate file becomes a symbolic link with the reason in the file name and appears in the same folder.

The following folders are created.

  • !replace
    • If you put a file in this folder, it will replace the existing file.
  • !dedupe
    • If yout put a file in this folder, it will delete the file. but the hash value is memorized.
  • !save
    • If yout put a file in this folder, it will import the file.
  • !transfer
    • It is similar to !replace, but the destination is a new file path, not a file path that already exists.

Dedupper processes based on “mark” given to these folders or file names. Normal behavior is overwritten by these “marks”.

You can distribute files to folders or rewrite “marks” to make final decisions. If you are satisfied with the “marks”, let’s run dedupper again.

Directories and symbolic links that have been used are automatically deleted.

Example

Folder/File name

  • aaa.!s.jpg
    • save mode.
  • !replace/aaa.!s.jpg
    • replace mode. File name mark ignored.
  • aaa.!r.jpg
    • replace file. It will replace first hit duplicated file.
  • bbb.!r2.png
    • replace file. It will replace bbb_x#2.REASON.png symlink destination.
      • “x” of “bbb_x” is simply collision avoidance of file names. You can ignore it.
      • The number after “#” is the identification number of the duplication candidate. In replace mode, it becomes impossible to know which image to replace when multiple duplicates are hit, so you can specify candidate numbers like !2r.

Case of some images

In this case only b02_1.!s.jpg is saved, others are deleted(erase) or deleted after the hash value is recorded(dedupe). Marks like !s in the file path are removed when importing.