How z1311/image-manipulation-detection works
1. This repository is a small Python inference pipeline for image-forgery detection. Its goal is to classify a single image as authentic or tampered using a two-level analysis flow described in the README.
2. The entry point is main.py, which exposes a CLI with a required -p/--path flag. The repository is therefore organized around one input artifact: an image file path.
3. Level 1 is metadata inspection, implemented in level1.py. This stage looks for software or editing signatures in the image metadata, so it acts as a fast, heuristic first pass before any heavier model inference.
4. Level 2 is the visual-analysis path. The repository uses Error Level Analysis in ela.py to transform the input image into a representation that highlights compression inconsistencies and potential tampered regions.
5. The ELA output is then passed into the CNN defined in model.py for final classification. The model is not trained at runtime; it uses a pre-trained weight file stored at model/model_c1.pth.
6. The training and validation workflow is separated from inference and appears to live in train.ipynb. That notebook likely produced the saved CNN weights used by the runtime pipeline.
7. The main architectural boundary is between preprocessing/detection logic and model inference:
- metadata analysis in Level 1
- ELA feature generation in Level 2
- CNN classification using persisted weights
8. The data flow is linear and file-centric: image path in, metadata inspection, optional or parallel ELA generation, CNN inference, classification output. There is no indication of a database, API server, or distributed system.
9. The model is trained on the CASIA dataset, specifically JPEG copy-move and spliced tampering examples. That dataset choice matters because it shapes the CNN’s expected input format and the types of manipulations the system is designed to detect.
10. From an architecture-diagram perspective, the key components to show are:
- CLI user input
- main.py orchestration
- level1.py metadata scanner
- ela.py preprocessing
- model.py / model/model_c1.pth inference engine
- final authentic-vs-tampered decision
11. The repo is self-contained and local: it depends on Python execution and a saved model artifact, with no obvious external services or runtime infrastructure beyond the filesystem and image-processing/model libraries implied by the implementation.
Main entry points: main.py Main · model.py CNN · level1.py Level 1 · ela.py ELA prep
Components 8
Entrypoint
CLI input and orchestration
- Image path · Required input image file path supplied via the CLI
- Main · CLI entrypoint that coordinates the two-level forgery detection flow
main.py - Verdict · Final classification output for the submitted image
Detection
Metadata and visual-analysis stages
Inference
CNN classification runtime
- CNN · Pretrained convolutional model that scores the ELA image for tampering
model.py
Artifacts
Persisted model weights
- Weights · Saved CNN parameters used at inference time
model/model_c1.pth
Training
Notebook used to produce runtime weights
- Training · Training and validation workflow that produced the saved CNN weights
train.ipynb
Connections 8
- Image path → Main: path input · The required image path is passed into the CLI entrypoint
- Main → Level 1: run metadata · Main invokes the Level 1 heuristic inspection
- Main → ELA prep: build ELA · Main prepares the visual-analysis branch for the same input image
- Level 1 → Verdict: heuristic signal · Metadata findings contribute to the overall tamper judgment
- ELA prep → CNN: ELA image · The transformed image is forwarded into the CNN classifier
- Weights → CNN: load params · The classifier uses the persisted checkpoint at runtime
- CNN → Verdict: classify · CNN output is turned into the final authentic-or-tampered verdict
- Training → Weights: produces · The notebook training workflow generates the saved model artifact