ESRGANとは?
拡散モデル(Stable Diffusionなど)が流行る前、画像生成の主役は GAN でした。
ESRGANは、その GAN 世代から引き継がれてきたアップスケール用のモデルです。
ESRGANは、低解像度の画像を高解像度にアップスケールするための 超解像GAN です。
ただ拡大するのではなく、「それっぽい細部」を描き足しながら 2〜4倍に拡大してくれます。
拡散モデルのアップスケールに比べて非常に軽量なので、いまだ活躍する機会は多いですね。
モデルのダウンロード
用途によってめちゃめちゃな数のモデルがありますが、ひとまず、以下のモデルを使ってみましょう。
RealESRGAN
ComfyUI Manager→Model ManagerRealESRGAN x4と検索してInstallしてください。
- 有志によって開発されたモデルが共有されています。
- クリーンアップに特化したモデルなどもあり、眺めているだけでも楽しめますね。
ESRGANでアップスケールする

{
"id": "a244ccf2-5842-47ed-a7fe-5252c37bb979",
"revision": 0,
"last_node_id": 5,
"last_link_id": 6,
"nodes": [
{
"id": 3,
"type": "UpscaleModelLoader",
"pos": [
451.29150787007677,
-191.52546058515136
],
"size": [
260,
58
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "UPSCALE_MODEL",
"type": "UPSCALE_MODEL",
"links": [
2
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.76",
"Node name for S&R": "UpscaleModelLoader"
},
"widgets_values": [
"RealESRGAN_x4.pth"
],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 1,
"type": "ImageUpscaleWithModel",
"pos": [
747.4225780470904,
-133.04868614724018
],
"size": [
247.4365767045455,
46
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"name": "upscale_model",
"type": "UPSCALE_MODEL",
"link": 2
},
{
"name": "image",
"type": "IMAGE",
"link": 1
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
6
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.76",
"Node name for S&R": "ImageUpscaleWithModel"
},
"color": "#232",
"bgcolor": "#353"
},
{
"id": 4,
"type": "SaveImage",
"pos": [
1029.6592249286493,
-133.04868614724018
],
"size": [
322.72727272727275,
387.2727272727272
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 6
}
],
"outputs": [],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.76"
},
"widgets_values": [
"ComfyUI"
]
},
{
"id": 2,
"type": "LoadImage",
"pos": [
451.29150787007677,
-75.36269847873763
],
"size": [
261.33100000000013,
357.303
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
1
]
},
{
"name": "MASK",
"type": "MASK",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.76",
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"A_01.jpg",
"image"
]
}
],
"links": [
[
1,
2,
0,
1,
1,
"IMAGE"
],
[
2,
3,
0,
1,
0,
"UPSCALE_MODEL"
],
[
6,
1,
0,
4,
0,
"IMAGE"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 0.9090909090909091,
"offset": [
82.10849212992323,
466.42546058515137
]
},
"frontendVersion": "1.34.6",
"VHS_latentpreview": false,
"VHS_latentpreviewrate": 0,
"VHS_MetadataImage": true,
"VHS_KeepIntermediate": true
},
"version": 0.4
}
- 🟩
Load Upscale Modelノードに任意のモデルを読み込みます。
倍率を修正する
RealESRGAN x4 のように大体のアップスケーラーには x4 のような文字があります。
これは倍率で、このモデルを使ってアップスケールすると 強制的に 4倍になります。
しかし、例えばHires.fixのworkflowに組み込むときなどは4倍だと大きすぎます。 こういったときはアップスケーラーで大きくした画像を縮小する処理を追加します。
workflow

{
"id": "a244ccf2-5842-47ed-a7fe-5252c37bb979",
"revision": 0,
"last_node_id": 5,
"last_link_id": 5,
"nodes": [
{
"id": 5,
"type": "ImageScaleBy",
"pos": [
1024.6577912673977,
-133.04868614724018
],
"size": [
210,
82
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"name": "image",
"type": "IMAGE",
"link": 4
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
5
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.76",
"Node name for S&R": "ImageScaleBy"
},
"widgets_values": [
"nearest-exact",
0.5
],
"color": "#432",
"bgcolor": "#653"
},
{
"id": 4,
"type": "SaveImage",
"pos": [
1263.9592249286482,
-133.04868614724018
],
"size": [
322.72727272727275,
387.2727272727272
],
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 5
}
],
"outputs": [],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.76"
},
"widgets_values": [
"ComfyUI"
]
},
{
"id": 1,
"type": "ImageUpscaleWithModel",
"pos": [
747.9197809016003,
-133.04868614724018
],
"size": [
247.4365767045455,
46
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"name": "upscale_model",
"type": "UPSCALE_MODEL",
"link": 2
},
{
"name": "image",
"type": "IMAGE",
"link": 1
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
4
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.76",
"Node name for S&R": "ImageUpscaleWithModel"
},
"widgets_values": [],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 3,
"type": "UpscaleModelLoader",
"pos": [
451.29150787007677,
-191.52546058515136
],
"size": [
260,
58
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "UPSCALE_MODEL",
"type": "UPSCALE_MODEL",
"links": [
2
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.76",
"Node name for S&R": "UpscaleModelLoader"
},
"widgets_values": [
"RealESRGAN_x4.pth"
],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 2,
"type": "LoadImage",
"pos": [
451.29150787007677,
-75.36269847873763
],
"size": [
261.33100000000013,
357.303
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
1
]
},
{
"name": "MASK",
"type": "MASK",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.76",
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"A_01.jpg",
"image"
]
}
],
"links": [
[
1,
2,
0,
1,
1,
"IMAGE"
],
[
2,
3,
0,
1,
0,
"UPSCALE_MODEL"
],
[
4,
1,
0,
5,
0,
"IMAGE"
],
[
5,
5,
0,
4,
0,
"IMAGE"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 1.1,
"offset": [
-190.3824169609858,
406.9800060396968
]
},
"frontendVersion": "1.34.6",
"VHS_latentpreview": false,
"VHS_latentpreviewrate": 0,
"VHS_MetadataImage": true,
"VHS_KeepIntermediate": true
},
"version": 0.4
}
- 🟨
scale_byの値を変更して倍率を調整できます。
GFPGANで顔だけ補正する
顔(Face)専用の復元GAN として GFPGAN というものがあります。
ノイズで崩れた顔を検出し、「学習済みのきれいな顔」に寄せて描き直すタイプのモデルです。
FaceSwapノードなどの後処理で「ついでに顔だけ整える」用途で登場することがあります。
詳しい使い方はここでは扱いませんが、「顔を専用に直す仕上げ用GANがある」 程度に覚えておけば十分です。