{"id":13672477,"url":"https://github.com/RimoChan/modnet-entry","last_synced_at":"2025-04-27T22:32:15.851Z","repository":{"id":109879851,"uuid":"600371135","full_name":"RimoChan/modnet-entry","owner":"RimoChan","description":"【MODNet-entry】开箱即用的人像抠图工具","archived":false,"fork":false,"pushed_at":"2023-02-11T09:50:43.000Z","size":5,"stargazers_count":172,"open_issues_count":2,"forks_count":16,"subscribers_count":2,"default_branch":"slave","last_synced_at":"2025-04-05T15:11:32.372Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RimoChan.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-02-11T09:30:03.000Z","updated_at":"2025-03-21T19:15:27.000Z","dependencies_parsed_at":"2023-05-03T07:01:06.314Z","dependency_job_id":null,"html_url":"https://github.com/RimoChan/modnet-entry","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RimoChan%2Fmodnet-entry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RimoChan%2Fmodnet-entry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RimoChan%2Fmodnet-entry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RimoChan%2Fmodnet-entry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RimoChan","download_url":"https://codeload.github.com/RimoChan/modnet-entry/tar.gz/refs/heads/slave","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251219601,"owners_count":21554444,"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-08-02T09:01:36.776Z","updated_at":"2025-04-27T22:32:15.559Z","avatar_url":"https://github.com/RimoChan.png","language":"Python","readme":"# 【MODNet-entry】开箱即用的人像抠图工具\n\n\n前几天我用stable-diffusion生成了几千张萝莉图片，准备用来做游戏立绘，但是它出的图都是带背景的……也不是不能抠啦，但是我一点手工活都不想做，所以就在GitHub上找了找有没有什么全自动抠人的模型。\n\n但是我找到的都没有方便的接口，一般都是给一个模型，然后给一堆代码，要自己加载自己调，很麻烦。所以我就给MODNet包了一层，可以直接用pip安装，这下就方便了！\n\n模型效果可以看[原仓库](https://github.com/ZHKKKe/MODNet)，我就不复制图片过来啦。\n\n\n## 安装\n\n```bash\npip install git+https://github.com/RimoChan/modnet-entry.git\n```\n\n安装时会从Google Drive下载预训练模型，所以要保证你的网络是好的。\n\n## 示例\n\n首先随便准备一张`test.png`，然后——\n\n```python\nfrom MODNet_entry import get_model, infer2\n\nmodel = get_model('modnet_photographic_portrait_matting.ckpt')\ninfer2(model, 'test.png', 'alpha.png', 'new_image.png')\n```\n\n这样就抠好啦，输出就是`alpha.png`和`new_image.png`这两张图。\n\n\n## 接口\n\n```python\ndef get_model(ckpt_name: str) -\u003e MODNet: ...\n```\n\n获取一个预训练的模型。\n\n参数: \n\n- `ckpt_name`: 模型的名字。只有`modnet_photographic_portrait_matting.ckpt`/`modnet_webcam_portrait_matting.ckpt`两种可选。\n\n\u003chr/\u003e\n\n```python\ndef infer(modnet: MODNet, im: np.ndarray[np.uint8], ref_size=1024) -\u003e np.ndarray[np.float32]: ...\n```\n\n输入一张图，预测alpha通道。\n\n参数: \n\n- `modnet`: 刚才加载的那个模型。\n\n- `im`: 图片。RGB或RGBA或灰度的uint8矩阵。\n\n- `ref_size`: 预测时如果图片的短边长于这个尺寸就缩小到这个尺寸。\n\n返回一个与原图相同大小的灰度float矩阵。\n\n\u003chr/\u003e\n\n```python\ndef infer2(modnet: MODNet, img_path: str, out_alpha_path: str = '', out_img_path: str = ''): ...\n```\n\n输入一个图片路径，将抠图结果保存在硬盘上。\n\n参数: \n\n- `modnet`: 刚才加载的那个模型。\n\n- `img_path`: 输入图片路径。\n\n- `out_alpha_path`: 输出alpha图片路径。\n\n- `out_img_path`: 输出抠好的图的路径。\n\n\n## 结束\n\n就这样，我要去看萝莉图片了，大家88！\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRimoChan%2Fmodnet-entry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRimoChan%2Fmodnet-entry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRimoChan%2Fmodnet-entry/lists"}