Skip to content

Commit fb699e0

Browse files
authored
Merge pull request AUTOMATIC1111#3 from mattyamonaca/develop
Develop
2 parents a18750f + a4dbd87 commit fb699e0

File tree

8 files changed

+627
-383
lines changed

8 files changed

+627
-383
lines changed

annotator/leres/leres/depthmap.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ def calculateprocessingres(img, basesize, confidence=0.1, scale_threshold=3, who
9999
grad[grad >= middle] = 1
100100

101101
# dilation kernel with size of the receptive field
102-
kernel = np.ones((int(basesize/speed_scale), int(basesize/speed_scale)), np.float)
102+
kernel = np.ones((int(basesize/speed_scale), int(basesize/speed_scale)), float)
103103
# dilation kernel with size of the a quarter of receptive field used to compute k
104104
# as described in section 6 of main paper
105-
kernel2 = np.ones((int(basesize / (4*speed_scale)), int(basesize / (4*speed_scale))), np.float)
105+
kernel2 = np.ones((int(basesize / (4*speed_scale)), int(basesize / (4*speed_scale))), float)
106106

107107
# Output resolution limit set by the whole_size_threshold and scale_threshold.
108108
threshold = min(whole_size_threshold, scale_threshold * max(img.shape[:2]))

annotator/uniformer/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def apply_uniformer(img):
2727
from basicsr.utils.download_util import load_file_from_url
2828
load_file_from_url(checkpoint_file, model_dir=modeldir)
2929

30-
model = init_segmentor(config_file, checkpoint_file)
30+
model = init_segmentor(config_file, modelpath)
3131
model = model.to(devices.get_device_for("controlnet"))
3232

3333
if devices.get_device_for("controlnet").type == 'mps':

example/api_img2img.ipynb

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"# controlnet + img2img\n",
10+
"# enable `Allow other script to control this extension` in settings\n",
11+
"\n",
12+
"import requests\n",
13+
"import cv2\n",
14+
"from base64 import b64encode\n",
15+
"\n",
16+
"def readImage(path):\n",
17+
" img = cv2.imread(path)\n",
18+
" retval, buffer = cv2.imencode('.jpg', img)\n",
19+
" b64img = b64encode(buffer).decode(\"utf-8\")\n",
20+
" return b64img\n",
21+
"\n",
22+
"b64img = readImage(\"/root/workspace/nahida/0e17302b9bfa15402f783c29c0d1d34f.jpg\")\n",
23+
"\n",
24+
"class controlnetRequest():\n",
25+
" def __init__(self, prompt):\n",
26+
" self.url = \"http://localhost:7860/controlnet/img2img\"\n",
27+
" self.body = {\n",
28+
" \"init_images\": [b64img],\n",
29+
" \"prompt\": prompt,\n",
30+
" \"negative_prompt\": \"\",\n",
31+
" \"seed\": -1,\n",
32+
" \"subseed\": -1,\n",
33+
" \"subseed_strength\": 0,\n",
34+
" \"batch_size\": 1,\n",
35+
" \"n_iter\": 1,\n",
36+
" \"steps\": 20,\n",
37+
" \"cfg_scale\": 7,\n",
38+
" \"width\": 512,\n",
39+
" \"height\": 768,\n",
40+
" \"restore_faces\": True,\n",
41+
" \"eta\": 0,\n",
42+
" \"sampler_index\": \"Euler a\",\n",
43+
" \"controlnet_input_image\": [b64img],\n",
44+
" \"controlnet_module\": 'canny',\n",
45+
" \"controlnet_model\": 'control_canny-fp16 [e3fe7712]',\n",
46+
" \"controlnet_guidance\": 1.0,\n",
47+
" }\n",
48+
"\n",
49+
" def sendRequest(self):\n",
50+
" r = requests.post(self.url, json=self.body)\n",
51+
" return r.json()\n",
52+
"\n",
53+
"js = controlnetRequest(\"walter white\").sendRequest()"
54+
]
55+
},
56+
{
57+
"cell_type": "code",
58+
"execution_count": null,
59+
"metadata": {},
60+
"outputs": [],
61+
"source": [
62+
"import io, base64\n",
63+
"import matplotlib.pyplot as plt\n",
64+
"from PIL import Image\n",
65+
"\n",
66+
"pil_img = Image.open('/root/workspace/nahida/0e17302b9bfa15402f783c29c0d1d34f.jpg')\n",
67+
"image = Image.open(io.BytesIO(base64.b64decode(js[\"images\"][0])))\n",
68+
"mask_image = Image.open(io.BytesIO(base64.b64decode(js[\"images\"][1])))\n",
69+
"\n",
70+
"plt.figure()\n",
71+
"f, axarr = plt.subplots(1,3) \n",
72+
"axarr[0].imshow(pil_img) \n",
73+
"axarr[1].imshow(image) \n",
74+
"axarr[2].imshow(mask_image) "
75+
]
76+
}
77+
],
78+
"metadata": {
79+
"kernelspec": {
80+
"display_name": "pynb",
81+
"language": "python",
82+
"name": "python3"
83+
},
84+
"language_info": {
85+
"codemirror_mode": {
86+
"name": "ipython",
87+
"version": 3
88+
},
89+
"file_extension": ".py",
90+
"mimetype": "text/x-python",
91+
"name": "python",
92+
"nbconvert_exporter": "python",
93+
"pygments_lexer": "ipython3",
94+
"version": "3.10.9"
95+
},
96+
"orig_nbformat": 4,
97+
"vscode": {
98+
"interpreter": {
99+
"hash": "d73345514d8c18d9a1da7351d222dbd2834c7f4a09e728a0d1f4c4580fbec206"
100+
}
101+
}
102+
},
103+
"nbformat": 4,
104+
"nbformat_minor": 2
105+
}

example/test_api.ipynb example/api_txt2img.ipynb

+41-22
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,11 @@
44
"cell_type": "code",
55
"execution_count": null,
66
"metadata": {},
7-
"outputs": [
8-
{
9-
"ename": "",
10-
"evalue": "",
11-
"output_type": "error",
12-
"traceback": [
13-
"\u001b[1;31mThe kernel failed to start as '/root/mambaforge/envs/webui/lib/python3.10/site-packages/psutil/_psutil_linux.cpython-310-x86_64-linux-gnu.so' could not be imported from '5.9.2 instead of 5.9.4'.\n",
14-
"\u001b[1;31mClick <a href='https://aka.ms/kernelFailuresModuleImportErrFromFile'>here</a> for more info."
15-
]
16-
}
17-
],
7+
"outputs": [],
188
"source": [
199
"# controlnet + txt2img\n",
10+
"# enable `Allow other script to control this extension` in settings\n",
11+
"\n",
2012
"import requests\n",
2113
"import cv2\n",
2214
"from base64 import b64encode\n",
@@ -27,12 +19,11 @@
2719
" b64img = b64encode(buffer).decode(\"utf-8\")\n",
2820
" return b64img\n",
2921
"\n",
30-
"\n",
31-
"b64img = readImage(\"test.png\")\n",
22+
"b64img = readImage(\"/root/workspace/nahida/0e17302b9bfa15402f783c29c0d1d34f.jpg\")\n",
3223
"\n",
3324
"class controlnetRequest():\n",
3425
" def __init__(self, prompt):\n",
35-
" self.url = \"http://localhost:7777/controlnet/txt2img\"\n",
26+
" self.url = \"http://localhost:7860/controlnet/txt2img\"\n",
3627
" self.body = {\n",
3728
" \"prompt\": prompt,\n",
3829
" \"negative_prompt\": \"\",\n",
@@ -44,39 +35,67 @@
4435
" \"steps\": 15,\n",
4536
" \"cfg_scale\": 7,\n",
4637
" \"width\": 512,\n",
47-
" \"height\": 512,\n",
38+
" \"height\": 768,\n",
4839
" \"restore_faces\": True,\n",
4940
" \"eta\": 0,\n",
5041
" \"sampler_index\": \"Euler a\",\n",
5142
" \"controlnet_input_image\": [b64img],\n",
52-
" \"controlnet_module\": 'openpose',\n",
53-
" \"controlnet_model\": 'control_sd15_openpose [fef5e48e]',\n",
43+
" \"controlnet_module\": 'canny',\n",
44+
" \"controlnet_model\": 'control_canny-fp16 [e3fe7712]',\n",
5445
" \"controlnet_guidance\": 1.0,\n",
5546
" }\n",
5647
"\n",
5748
" def sendRequest(self):\n",
5849
" r = requests.post(self.url, json=self.body)\n",
5950
" return r.json()\n",
6051
"\n",
61-
"js = controlnetRequest(\"walter white\").sendRequest()\n",
62-
"print(js)"
52+
"js = controlnetRequest(\"walter white\").sendRequest()"
53+
]
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": null,
58+
"metadata": {},
59+
"outputs": [],
60+
"source": [
61+
"import io, base64\n",
62+
"import matplotlib.pyplot as plt\n",
63+
"from PIL import Image\n",
64+
"\n",
65+
"pil_img = Image.open('/root/workspace/nahida/0e17302b9bfa15402f783c29c0d1d34f.jpg')\n",
66+
"image = Image.open(io.BytesIO(base64.b64decode(js[\"images\"][0])))\n",
67+
"mask_image = Image.open(io.BytesIO(base64.b64decode(js[\"images\"][1])))\n",
68+
"\n",
69+
"plt.figure()\n",
70+
"f, axarr = plt.subplots(1,3) \n",
71+
"axarr[0].imshow(pil_img) \n",
72+
"axarr[1].imshow(image) \n",
73+
"axarr[2].imshow(mask_image) "
6374
]
6475
}
6576
],
6677
"metadata": {
6778
"kernelspec": {
68-
"display_name": "webui",
79+
"display_name": "pynb",
6980
"language": "python",
7081
"name": "python3"
7182
},
7283
"language_info": {
84+
"codemirror_mode": {
85+
"name": "ipython",
86+
"version": 3
87+
},
88+
"file_extension": ".py",
89+
"mimetype": "text/x-python",
7390
"name": "python",
74-
"version": "3.10.8"
91+
"nbconvert_exporter": "python",
92+
"pygments_lexer": "ipython3",
93+
"version": "3.10.9"
7594
},
7695
"orig_nbformat": 4,
7796
"vscode": {
7897
"interpreter": {
79-
"hash": "bfdc572d05de84b0e25b3cefadad3fe196a31650b582a0267180110287606d68"
98+
"hash": "d73345514d8c18d9a1da7351d222dbd2834c7f4a09e728a0d1f4c4580fbec206"
8099
}
81100
}
82101
},

0 commit comments

Comments
 (0)