Spaces:
Runtime error
Runtime error
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -8,6 +8,7 @@ from io import BytesIO
|
|
| 8 |
from PIL import Image
|
| 9 |
import requests
|
| 10 |
import re
|
|
|
|
| 11 |
|
| 12 |
class ImageType(Enum):
|
| 13 |
REAL_UP_L = 0
|
|
@@ -74,3 +75,13 @@ def image_to_base64(image_array):
|
|
| 74 |
image_array.save(buffered, format="PNG")
|
| 75 |
image_b64 = base64.b64encode(buffered.getvalue()).decode("utf-8")
|
| 76 |
return f"data:image/png;base64, {image_b64}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
from PIL import Image
|
| 9 |
import requests
|
| 10 |
import re
|
| 11 |
+
from copy import deepcopy
|
| 12 |
|
| 13 |
class ImageType(Enum):
|
| 14 |
REAL_UP_L = 0
|
|
|
|
| 75 |
image_array.save(buffered, format="PNG")
|
| 76 |
image_b64 = base64.b64encode(buffered.getvalue()).decode("utf-8")
|
| 77 |
return f"data:image/png;base64, {image_b64}"
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def copy_G_params(model):
|
| 81 |
+
flatten = deepcopy(list(p.data for p in model.parameters()))
|
| 82 |
+
return flatten
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def load_params(model, new_param):
|
| 86 |
+
for p, new_p in zip(model.parameters(), new_param):
|
| 87 |
+
p.data.copy_(new_p)
|