recoilme commited on
Commit
e3d03e3
·
1 Parent(s): 7d2e6b0
Untitled.ipynb ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "7efc5ac3-1568-4d92-8361-e3ef6a00e9fd",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "ename": "ImportError",
11
+ "evalue": "cannot import name 'SwinIRForImageSuperResolution' from 'transformers' (/usr/local/lib/python3.12/dist-packages/transformers/__init__.py)",
12
+ "output_type": "error",
13
+ "traceback": [
14
+ "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
15
+ "\u001b[31mImportError\u001b[39m Traceback (most recent call last)",
16
+ "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[1]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mtransformers\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m SwinIRForImageSuperResolution\n\u001b[32m 2\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mtorch\u001b[39;00m\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mPIL\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m Image\n",
17
+ "\u001b[31mImportError\u001b[39m: cannot import name 'SwinIRForImageSuperResolution' from 'transformers' (/usr/local/lib/python3.12/dist-packages/transformers/__init__.py)"
18
+ ]
19
+ }
20
+ ],
21
+ "source": [
22
+ "from transformers import SwinIRForImageSuperResolution\n",
23
+ "import torch\n",
24
+ "from PIL import Image\n",
25
+ "\n",
26
+ "model = SwinIRForImageSuperResolution.from_pretrained(\"caidas/swinir-large-2x\")\n",
27
+ "image = Image.open(\"/workspace/simplevae2x/123456789.jpg\")\n",
28
+ "inputs = model.pixel_values(image, return_tensors=\"pt\")\n",
29
+ "outputs = model(inputs)\n",
30
+ "output_image = outputs.pixel_values[0].permute(1, 2, 0).numpy()\n",
31
+ "output_image = (output_image * 255).astype(\"uint8\")\n",
32
+ "Image.fromarray(output_image).save(\"output.jpg\")\n"
33
+ ]
34
+ },
35
+ {
36
+ "cell_type": "code",
37
+ "execution_count": 2,
38
+ "id": "dd10133d-ecfb-4bd5-8647-539aab4b1124",
39
+ "metadata": {},
40
+ "outputs": [
41
+ {
42
+ "ename": "ImportError",
43
+ "evalue": "cannot import name 'RealESRGANForImageSuperResolution' from 'transformers' (/usr/local/lib/python3.12/dist-packages/transformers/__init__.py)",
44
+ "output_type": "error",
45
+ "traceback": [
46
+ "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
47
+ "\u001b[31mImportError\u001b[39m Traceback (most recent call last)",
48
+ "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[2]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mtransformers\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m RealESRGANForImageSuperResolution, RealESRGANImageProcessor\n\u001b[32m 2\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mPIL\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m Image\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mrequests\u001b[39;00m\n",
49
+ "\u001b[31mImportError\u001b[39m: cannot import name 'RealESRGANForImageSuperResolution' from 'transformers' (/usr/local/lib/python3.12/dist-packages/transformers/__init__.py)"
50
+ ]
51
+ }
52
+ ],
53
+ "source": [
54
+ "from transformers import RealESRGANForImageSuperResolution, RealESRGANImageProcessor\n",
55
+ "from PIL import Image\n",
56
+ "import requests\n",
57
+ "\n",
58
+ "# Загрузка модели и процессора\n",
59
+ "model = RealESRGANForImageSuperResolution.from_pretrained(\"nateraw/real-esrgan\")\n",
60
+ "processor = RealESRGANImageProcessor()\n",
61
+ "\n",
62
+ "# Загрузка и подготовка изображения\n",
63
+ "url = \"http://images.cocodataset.org/val2017/000000039769.jpg\"\n",
64
+ "image = Image.open(requests.get(url, stream=True).raw)\n",
65
+ "\n",
66
+ "# Предобработка изображения\n",
67
+ "inputs = processor(images=image, return_tensors=\"pt\")\n",
68
+ "\n",
69
+ "# Инференс\n",
70
+ "outputs = model(**inputs)\n",
71
+ "\n",
72
+ "# Постобработка и сохранение результата\n",
73
+ "output = outputs.pixel_values[0].permute(1, 2, 0).numpy()\n",
74
+ "output = processor.postprocess(output, output_type=\"pil\")\n",
75
+ "output.save(\"output.jpg\")\n"
76
+ ]
77
+ },
78
+ {
79
+ "cell_type": "code",
80
+ "execution_count": 3,
81
+ "id": "7cc6d952-a5cb-44a7-80a8-a2cf279d00d0",
82
+ "metadata": {},
83
+ "outputs": [
84
+ {
85
+ "ename": "ModuleNotFoundError",
86
+ "evalue": "No module named 'realesrgan'",
87
+ "output_type": "error",
88
+ "traceback": [
89
+ "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
90
+ "\u001b[31mModuleNotFoundError\u001b[39m Traceback (most recent call last)",
91
+ "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[3]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mrealesrgan\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m RealESRGAN\n\u001b[32m 2\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mPIL\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m Image\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mtorch\u001b[39;00m\n",
92
+ "\u001b[31mModuleNotFoundError\u001b[39m: No module named 'realesrgan'"
93
+ ]
94
+ }
95
+ ],
96
+ "source": [
97
+ "from realesrgan import RealESRGAN\n",
98
+ "from PIL import Image\n",
99
+ "import torch\n",
100
+ "\n",
101
+ "# Загружаем модель\n",
102
+ "device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')\n",
103
+ "model = RealESRGAN(device, scale=2)\n",
104
+ "model.load_weights('RealESRGAN_x2.pth') # если нет — скачай заранее\n",
105
+ "\n",
106
+ "# Открываем изображение\n",
107
+ "image = Image.open('/workspace/simplevae2x/123456789.jpg').convert('RGB')\n",
108
+ "\n",
109
+ "# Апскейл\n",
110
+ "sr_image = model.predict(image)\n",
111
+ "\n",
112
+ "# Сохраняем\n",
113
+ "sr_image.save('output.png')\n"
114
+ ]
115
+ },
116
+ {
117
+ "cell_type": "code",
118
+ "execution_count": 4,
119
+ "id": "87fb3261-550d-4df1-9cba-879be405cd4b",
120
+ "metadata": {},
121
+ "outputs": [
122
+ {
123
+ "ename": "ModuleNotFoundError",
124
+ "evalue": "No module named 'realesrgan'",
125
+ "output_type": "error",
126
+ "traceback": [
127
+ "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
128
+ "\u001b[31mModuleNotFoundError\u001b[39m Traceback (most recent call last)",
129
+ "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[4]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mtorch\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mrealesrgan\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m RealESRGANer\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mbasicsr\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01marchs\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mrrdbnet_arch\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m RRDBNet\n\u001b[32m 4\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mPIL\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m Image\n",
130
+ "\u001b[31mModuleNotFoundError\u001b[39m: No module named 'realesrgan'"
131
+ ]
132
+ }
133
+ ],
134
+ "source": [
135
+ "import torch\n",
136
+ "from realesrgan import RealESRGANer\n",
137
+ "from basicsr.archs.rrdbnet_arch import RRDBNet\n",
138
+ "from PIL import Image\n",
139
+ "\n",
140
+ "# Настраиваем модель\n",
141
+ "model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=2)\n",
142
+ "upsampler = RealESRGANer(\n",
143
+ " scale=2,\n",
144
+ " model_path='RealESRGAN_x2plus.pth',\n",
145
+ " model=model,\n",
146
+ " half=torch.cuda.is_available()\n",
147
+ ")\n",
148
+ "\n",
149
+ "# Загружаем изображение\n",
150
+ "img = Image.open('input.jpg').convert('RGB')\n",
151
+ "img = np.array(img)[..., ::-1] # PIL -> BGR\n",
152
+ "\n",
153
+ "# Апскейлим\n",
154
+ "output, _ = upsampler.enhance(img, outscale=2)\n",
155
+ "\n",
156
+ "# Сохраняем\n",
157
+ "cv2.imwrite('output.png', output)\n"
158
+ ]
159
+ },
160
+ {
161
+ "cell_type": "code",
162
+ "execution_count": null,
163
+ "id": "fc380493-5e87-45af-9be1-7bf0ee80f512",
164
+ "metadata": {},
165
+ "outputs": [],
166
+ "source": [
167
+ "!"
168
+ ]
169
+ }
170
+ ],
171
+ "metadata": {
172
+ "kernelspec": {
173
+ "display_name": "Python 3 (ipykernel)",
174
+ "language": "python",
175
+ "name": "python3"
176
+ },
177
+ "language_info": {
178
+ "codemirror_mode": {
179
+ "name": "ipython",
180
+ "version": 3
181
+ },
182
+ "file_extension": ".py",
183
+ "mimetype": "text/x-python",
184
+ "name": "python",
185
+ "nbconvert_exporter": "python",
186
+ "pygments_lexer": "ipython3",
187
+ "version": "3.12.3"
188
+ }
189
+ },
190
+ "nbformat": 4,
191
+ "nbformat_minor": 5
192
+ }
samples/sample_decoded_0.jpg CHANGED

Git LFS Details

  • SHA256: 2f1021860743f49ec696b96c62e29d523d6a9ccf9545d50c3393f46f57a533aa
  • Pointer size: 131 Bytes
  • Size of remote file: 126 kB

Git LFS Details

  • SHA256: ff7740f4fce410cf922474dc478c3d09d18b063eeccb5b9c4d94cd39aeb818de
  • Pointer size: 131 Bytes
  • Size of remote file: 128 kB
samples/sample_decoded_1.jpg CHANGED

Git LFS Details

  • SHA256: be327b54326fd9b72b7f820daa741a4772da1d86d1fdb001b7a734847e81a0cd
  • Pointer size: 130 Bytes
  • Size of remote file: 67.8 kB

Git LFS Details

  • SHA256: 65dcae6ca48de156066ac2a84be3301deb0a5ec90cb4c0abae1eb4f8fd6bea0d
  • Pointer size: 130 Bytes
  • Size of remote file: 68.8 kB
samples/sample_decoded_2.jpg CHANGED

Git LFS Details

  • SHA256: 96acd5408d5663290d43cf4f5914e728d912921e5a5a457218704e6eee85ba00
  • Pointer size: 130 Bytes
  • Size of remote file: 68.5 kB

Git LFS Details

  • SHA256: d2c4d9163af4168163e02c4e714f756f74d84004ed959a7dd3411b921b820800
  • Pointer size: 130 Bytes
  • Size of remote file: 68.5 kB
vae5/diffusion_pytorch_model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:4c5ffc5eee262853f4efc58092a8c3c1e268eeb74447e743f4ec2f8441358373
3
  size 382598708
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a00dd5f7c1636aecde772b6370caac921ff74af433dd82bdd2162282bf434143
3
  size 382598708