{"id":19984543,"url":"https://github.com/intellabs/dfm","last_synced_at":"2025-05-04T06:33:17.148Z","repository":{"id":148596818,"uuid":"512806718","full_name":"IntelLabs/dfm","owner":"IntelLabs","description":"DFM (Deep Feature Modeling) is an efficient and principled method for out-of-distribution detection, novelty and anomaly detection.","archived":false,"fork":false,"pushed_at":"2023-11-18T10:10:16.000Z","size":2295,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2023-11-19T06:55:16.659Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://intellabs.github.io/dfm/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IntelLabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-07-11T15:14:51.000Z","updated_at":"2023-09-13T23:40:30.000Z","dependencies_parsed_at":"2023-11-15T20:27:17.111Z","dependency_job_id":"8a95aa59-533d-4e61-9fb9-4f142f6c6e9a","html_url":"https://github.com/IntelLabs/dfm","commit_stats":null,"previous_names":[],"tags_count":1,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IntelLabs%2Fdfm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IntelLabs%2Fdfm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IntelLabs%2Fdfm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IntelLabs%2Fdfm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IntelLabs","download_url":"https://codeload.github.com/IntelLabs/dfm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224386378,"owners_count":17302652,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T04:19:27.743Z","updated_at":"2025-05-04T06:33:17.130Z","avatar_url":"https://github.com/IntelLabs.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PROJECT NOT UNDER ACTIVE MANAGEMENT #  \nThis project will no longer be maintained by Intel.  \nIntel has ceased development and contributions including, but not limited to, maintenance, bug fixes, new releases, or updates, to this project.  \nIntel no longer accepts patches to this project.  \n If you have an ongoing need to use this project, are interested in independently developing it, or would like to maintain patches for the open source software community, please create your own fork of this project.  \n  \n# Anomaly Detection using Feature Reconstruction Error from Deep Features\n\n### Introduction\n\nThis repo presents a fast, principled approach for detecting anomalous and out-of-distribution (OOD) samples in deep neural networks (DNN). We propose the application of linear statistical dimensionality reduction techniques on the semantic features produced by a DNN, in order to capture the low-dimensional subspace truly spanned by said features. We show that the feature reconstruction error (FRE), which is the l2-norm of the difference between the original feature in the high-dimensional space and the pre-image of its low-dimensional reduced embedding, is highly effective for OOD and anomaly detection. This dimensionality reduction can be performed using either Principal Component Analysis (PCA), or via a shallow (single layer) linear auto-encoder (AE). In case of the AE, if the weights are shared between the encoder and decoder, i.e $W_{dec} = W_{enc}^T$, then it converges to the same solution as the PCA. Experiments using standard image datasets and DNN architectures demonstrate that our method meets or exceeds best-in-class quality performance, but at a fraction of the computational and memory cost required by the state of the art. It can be trained and run very efficiently.\n\n### Dependencies\n\nFollowing modules are needed and can be installed using `python -m pip install -r requirements.txt`: \n\n- numpy  \n- scikit-learn  \n- PIL  \n- torch  \n- torchvision  \n- pandas\n\n### Dataset\n\nDownload the entire MVTec Anomaly Detection dataset (about 4.9 GB) from the [MVTec](https://www.mvtec.com/company/research/datasets/mvtec-ad) website and store it in a local folder. Recommended default folder location: `./mvtec`. Direct [link](https://www.mydrive.ch/shares/38536/3830184030e49fe74747669442f0f282/download/420938113-1629952094/mvtec_anomaly_detection.tar.xz) to dataset.\n\n### Running the code \n\nTo run the code:\n\n```bash\npython run_mvtec.py\n```\n\nBy default, `python run_mvtec.py` will run all 15 object categories in the MVTEC dataset with an *EfficientNet B5* backbone assuming that the dataset is stored in `./mvtec` folder (default location assumed by the script).\n    \nIf the dataset is stored in a different folder, its location can be specified by:\n\n```bash\npython run_mvtec.py --dataset_directory \u003cMVTec dataset path\u003e\n```\n    \nTwo other backbones are supported: Resnet18 and Resnet50. To run with a different backbone:\n    \n```bash\npython run_mvtec.py --model resnet18\n```\n\nThree dimensionality reduction methods are supported: pca, tae (Tied AE), ae (plain AE without shared weights) and any one or more of them can be optionally specified (default: all three modes are run). For example, the command line below will generate results for both PCA and Tied AE. Additionally, the number of training epochs can be optionally be specified if one of the modes being run is a type of AE (default: 250):\n    \n```bash\npython run_mvtec.py --modes pca tae --epochs 200\n```\n\nTo save the heatmaps used for anomaly segmentation, use the `--save_heatmaps` option and specify an optional output path (default: `.output`):\n```bash\npython run_mvtec.py --save_heatmaps --output_path results\n```\n    \nTo run on GPU:\n\n```bash\npython run_mvtec.py --gpu\n```\n    \nTo run a specific category from MVTec, provide category name. For example, :\n\n```bash\npython run_mvtec.py --object_category hazelnut\n```\n    \nSample commands using all options\n\n```bash\npython run_mvtec.py --dataset_directory \u003cMVTec dataset path\u003e --model resnet18 --object_category hazelnut --gpu --modes pca --save_heatmaps\n```\n\n### Reference \nThis code is based on the following work. Please cite if you use it.\n\n```tex\n@inproceedings{fre2023,\n  title={FRE: A Fast Method For Anomaly Detection And Segmentation},\n  author={Ibrahima J. Ndiour and\n          Nilesh A. Ahuja and\n          Utku Genc and\n          Omesh Tickoo}\n  booktitle={British Machine Vision Conference (BMVC)},\n  year={2023},\n}\n```\n\n\u003c!--\n[arxiv version](https://arxiv.org/abs/2203.10422):\n```\n@misc{https://doi.org/10.48550/arxiv.2203.10422,\n  doi = {10.48550/ARXIV.2203.10422},  \n  url = {https://arxiv.org/abs/2203.10422},  \n  author = {Ndiour, Ibrahima J. and Ahuja, Nilesh A. and Tickoo, Omesh},  \n  keywords = {Machine Learning (cs.LG), FOS: Computer and information sciences, FOS: Computer and information sciences},  \n  title = {Subspace Modeling for Fast Out-Of-Distribution and Anomaly Detection},  \n  publisher = {arXiv},  \n  year = {2022},  \n  copyright = {arXiv.org perpetual, non-exclusive license}\n}\n```\n--\u003e\n\n\u003c!-- Reviewed 9/11/23 michaelbeale-il --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintellabs%2Fdfm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fintellabs%2Fdfm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintellabs%2Fdfm/lists"}