Spaces:
Runtime error
Runtime error
new color classification (standard)
Browse files- .gitignore +2 -1
- DisentanglementBase.py +15 -5
- data/grammar_ornaments/1_colors_generally.png +3 -0
- data/grammar_ornaments/2_proportions_and_contrasts.png +3 -0
- data/grammar_ornaments/3_positions_simultanous.png +3 -0
- data/grammar_ornaments/4_juxtapositions.png +3 -0
- grammar_ornament_test.ipynb +256 -0
- interfacegan_colour_disentanglement.ipynb +145 -16
- structure_annotations.ipynb +0 -0
.gitignore
CHANGED
|
@@ -189,4 +189,5 @@ cython_debug/
|
|
| 189 |
data/images/
|
| 190 |
tmp/
|
| 191 |
figures/
|
| 192 |
-
archive/
|
|
|
|
|
|
| 189 |
data/images/
|
| 190 |
tmp/
|
| 191 |
figures/
|
| 192 |
+
archive/
|
| 193 |
+
segment-anything/
|
DisentanglementBase.py
CHANGED
|
@@ -181,12 +181,20 @@ class DisentanglementBase:
|
|
| 181 |
bins = [(x-1) * 360 / (len(self.colors_list) - 1) if x != 1
|
| 182 |
else 1 for x in range(len(self.colors_list) + 1)]
|
| 183 |
bins[0] = 0
|
|
|
|
| 184 |
y_cat = pd.cut(y,
|
| 185 |
bins=bins,
|
| 186 |
labels=self.colors_list,
|
| 187 |
include_lowest=True
|
| 188 |
)
|
| 189 |
print(y_cat.value_counts())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
x_train, x_val, y_train, y_val = train_test_split(X, y_cat, test_size=0.2)
|
| 191 |
else:
|
| 192 |
if extremes:
|
|
@@ -567,11 +575,13 @@ def main():
|
|
| 567 |
with dnnlib.util.open_url(model_file) as f:
|
| 568 |
model = legacy.load_network_pkl(f)['G_ema'] # type: ignore
|
| 569 |
|
| 570 |
-
colors_list = ['Red', 'Orange', 'Yellow', 'Yellow Green', 'Chartreuse Green',
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
colors_list = ['Gray', 'Red Orange', 'Yellow', 'Green', 'Light Blue',
|
| 574 |
-
|
|
|
|
|
|
|
| 575 |
|
| 576 |
scores = []
|
| 577 |
kwargs = {'CL method':['LR', 'SVM'], 'C':[0.1, 1], 'sign':[True, False],
|
|
|
|
| 181 |
bins = [(x-1) * 360 / (len(self.colors_list) - 1) if x != 1
|
| 182 |
else 1 for x in range(len(self.colors_list) + 1)]
|
| 183 |
bins[0] = 0
|
| 184 |
+
|
| 185 |
y_cat = pd.cut(y,
|
| 186 |
bins=bins,
|
| 187 |
labels=self.colors_list,
|
| 188 |
include_lowest=True
|
| 189 |
)
|
| 190 |
print(y_cat.value_counts())
|
| 191 |
+
|
| 192 |
+
y_h_cat[y_s == 0] = 'Gray'
|
| 193 |
+
y_h_cat[y_s == 100] = 'Gray'
|
| 194 |
+
y_h_cat[y_v == 0] = 'Gray'
|
| 195 |
+
y_h_cat[y_v == 100] = 'Gray'
|
| 196 |
+
|
| 197 |
+
print(y_cat.value_counts())
|
| 198 |
x_train, x_val, y_train, y_val = train_test_split(X, y_cat, test_size=0.2)
|
| 199 |
else:
|
| 200 |
if extremes:
|
|
|
|
| 575 |
with dnnlib.util.open_url(model_file) as f:
|
| 576 |
model = legacy.load_network_pkl(f)['G_ema'] # type: ignore
|
| 577 |
|
| 578 |
+
# colors_list = ['Red', 'Orange', 'Yellow', 'Yellow Green', 'Chartreuse Green',
|
| 579 |
+
# 'Kelly Green', 'Green Blue Seafoam', 'Cyan Blue',
|
| 580 |
+
# 'Warm Blue', 'Indigo', 'Purple Magenta', 'Magenta Pink']
|
| 581 |
+
# colors_list = ['Gray', 'Red Orange', 'Yellow', 'Green', 'Light Blue',
|
| 582 |
+
# 'Blue', 'Purple', 'Pink']
|
| 583 |
+
colors_list = ['Gray', 'Red', 'Yellow', 'Green', 'Cyan',
|
| 584 |
+
'Blue', 'Magenta']
|
| 585 |
|
| 586 |
scores = []
|
| 587 |
kwargs = {'CL method':['LR', 'SVM'], 'C':[0.1, 1], 'sign':[True, False],
|
data/grammar_ornaments/1_colors_generally.png
ADDED
|
Git LFS Details
|
data/grammar_ornaments/2_proportions_and_contrasts.png
ADDED
|
Git LFS Details
|
data/grammar_ornaments/3_positions_simultanous.png
ADDED
|
Git LFS Details
|
data/grammar_ornaments/4_juxtapositions.png
ADDED
|
Git LFS Details
|
grammar_ornament_test.ipynb
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": null,
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"outputs": [],
|
| 8 |
+
"source": [
|
| 9 |
+
"import os \n",
|
| 10 |
+
"from glob import glob \n",
|
| 11 |
+
"import pandas as pd\n",
|
| 12 |
+
"import numpy as np\n",
|
| 13 |
+
"\n",
|
| 14 |
+
"from PIL import Image, ImageColor\n",
|
| 15 |
+
"import extcolors\n",
|
| 16 |
+
"\n",
|
| 17 |
+
"import matplotlib.pyplot as plt\n",
|
| 18 |
+
"\n",
|
| 19 |
+
"import torch\n",
|
| 20 |
+
"\n",
|
| 21 |
+
"import dnnlib \n",
|
| 22 |
+
"import legacy\n",
|
| 23 |
+
"\n",
|
| 24 |
+
"\n",
|
| 25 |
+
"%load_ext autoreload\n",
|
| 26 |
+
"%autoreload 2"
|
| 27 |
+
]
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"cell_type": "code",
|
| 31 |
+
"execution_count": null,
|
| 32 |
+
"metadata": {},
|
| 33 |
+
"outputs": [],
|
| 34 |
+
"source": [
|
| 35 |
+
"images_textiles = glob('/Users/ludovicaschaerf/Desktop/TextAIles/TextileGAN/Original Textiles/*')"
|
| 36 |
+
]
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"cell_type": "markdown",
|
| 40 |
+
"metadata": {},
|
| 41 |
+
"source": [
|
| 42 |
+
"### LAWS\n",
|
| 43 |
+
"\n",
|
| 44 |
+
"1. primary colours on small surfaces and secondary or tertiary colors on large backgrounds\n",
|
| 45 |
+
"2. primary in upper portions and sec/third in lower portions of objects\n",
|
| 46 |
+
"3. primaries of equal intensities harmonize, secondaries harmonized by opposite primary in equal intensity, tertiary by remaining secondary\n",
|
| 47 |
+
"4. a full colors contrasted by a lower tone color should have the latter in larger proportion\n",
|
| 48 |
+
"5. when a primary has a hue (second coloration) of another primary, the secondary must have the hue of the third primary\n",
|
| 49 |
+
"6. blue in concave surfaces, yellow in convex, red in undersites\n",
|
| 50 |
+
"7. if too much of a color, the other colors should have the hue version without that color\n",
|
| 51 |
+
"8. all three primaries should be present\n",
|
| 52 |
+
"9. ..."
|
| 53 |
+
]
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"cell_type": "markdown",
|
| 57 |
+
"metadata": {},
|
| 58 |
+
"source": [
|
| 59 |
+
"Test 1\n",
|
| 60 |
+
"\n",
|
| 61 |
+
"primary - secondary - tertiary "
|
| 62 |
+
]
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
"cell_type": "code",
|
| 66 |
+
"execution_count": null,
|
| 67 |
+
"metadata": {},
|
| 68 |
+
"outputs": [],
|
| 69 |
+
"source": [
|
| 70 |
+
"def get_color_rank(hue, saturation, value):\n",
|
| 71 |
+
" if value < 5:\n",
|
| 72 |
+
" color = 'Black'\n",
|
| 73 |
+
" rank = 'None'\n",
|
| 74 |
+
" elif saturation < 3:\n",
|
| 75 |
+
" color = 'White'\n",
|
| 76 |
+
" rank = 'None'\n",
|
| 77 |
+
" elif saturation < 15:\n",
|
| 78 |
+
" color = 'Gray'\n",
|
| 79 |
+
" rank = 'None'\n",
|
| 80 |
+
" elif hue == 0:\n",
|
| 81 |
+
" color = 'Gray'\n",
|
| 82 |
+
" rank = 'None'\n",
|
| 83 |
+
" \n",
|
| 84 |
+
" elif hue >= 330 or hue <= 15:\n",
|
| 85 |
+
" color = 'Red'\n",
|
| 86 |
+
" rank = 'Primary'\n",
|
| 87 |
+
" elif hue > 15 and hue < 25:\n",
|
| 88 |
+
" color = 'Red Orange'\n",
|
| 89 |
+
" rank = 'Tertiary'\n",
|
| 90 |
+
" elif hue >= 25 and hue <= 40:\n",
|
| 91 |
+
" color = 'Orange'\n",
|
| 92 |
+
" rank = 'Secondary'\n",
|
| 93 |
+
" elif hue > 40 and hue < 50:\n",
|
| 94 |
+
" color = 'Orange Yellow'\n",
|
| 95 |
+
" rank = 'Tertiary'\n",
|
| 96 |
+
" elif hue >= 50 and hue <= 85:\n",
|
| 97 |
+
" color = 'Yellow'\n",
|
| 98 |
+
" rank = 'Primary'\n",
|
| 99 |
+
" elif hue > 85 and hue < 95:\n",
|
| 100 |
+
" color = 'Yellow Green'\n",
|
| 101 |
+
" rank = 'Tertiary'\n",
|
| 102 |
+
" elif hue >= 95 and hue <= 145:\n",
|
| 103 |
+
" color = 'Green'\n",
|
| 104 |
+
" rank = 'Secondary'\n",
|
| 105 |
+
" elif hue >= 145 and hue < 180:\n",
|
| 106 |
+
" color = 'Green Blue'\n",
|
| 107 |
+
" rank = 'Tertiary'\n",
|
| 108 |
+
" elif hue >= 180 and hue <= 245:\n",
|
| 109 |
+
" color = 'Blue'\n",
|
| 110 |
+
" rank = 'Primary'\n",
|
| 111 |
+
" elif hue > 245 and hue < 265:\n",
|
| 112 |
+
" color = 'Blue Violet'\n",
|
| 113 |
+
" rank = 'Tertiary'\n",
|
| 114 |
+
" elif hue >= 265 and hue <= 290:\n",
|
| 115 |
+
" color = 'Violet'\n",
|
| 116 |
+
" rank = 'Secondary'\n",
|
| 117 |
+
" elif hue > 290 and hue < 330:\n",
|
| 118 |
+
" color = 'Violet Red'\n",
|
| 119 |
+
" rank = 'Tertiary'\n",
|
| 120 |
+
" return color, rank"
|
| 121 |
+
]
|
| 122 |
+
},
|
| 123 |
+
{
|
| 124 |
+
"cell_type": "code",
|
| 125 |
+
"execution_count": null,
|
| 126 |
+
"metadata": {},
|
| 127 |
+
"outputs": [],
|
| 128 |
+
"source": [
|
| 129 |
+
"def rgb2hsv(r, g, b):\n",
|
| 130 |
+
" # Normalize R, G, B values\n",
|
| 131 |
+
" r, g, b = r / 255.0, g / 255.0, b / 255.0\n",
|
| 132 |
+
" \n",
|
| 133 |
+
" # h, s, v = hue, saturation, value\n",
|
| 134 |
+
" max_rgb = max(r, g, b) \n",
|
| 135 |
+
" min_rgb = min(r, g, b) \n",
|
| 136 |
+
" difference = max_rgb-min_rgb \n",
|
| 137 |
+
" \n",
|
| 138 |
+
" # if max_rgb and max_rgb are equal then h = 0\n",
|
| 139 |
+
" if max_rgb == min_rgb:\n",
|
| 140 |
+
" h = 0\n",
|
| 141 |
+
" \n",
|
| 142 |
+
" # if max_rgb==r then h is computed as follows\n",
|
| 143 |
+
" elif max_rgb == r:\n",
|
| 144 |
+
" h = (60 * ((g - b) / difference) + 360) % 360\n",
|
| 145 |
+
" \n",
|
| 146 |
+
" # if max_rgb==g then compute h as follows\n",
|
| 147 |
+
" elif max_rgb == g:\n",
|
| 148 |
+
" h = (60 * ((b - r) / difference) + 120) % 360\n",
|
| 149 |
+
" \n",
|
| 150 |
+
" # if max_rgb=b then compute h\n",
|
| 151 |
+
" elif max_rgb == b:\n",
|
| 152 |
+
" h = (60 * ((r - g) / difference) + 240) % 360\n",
|
| 153 |
+
" \n",
|
| 154 |
+
" # if max_rgb==zero then s=0\n",
|
| 155 |
+
" if max_rgb == 0:\n",
|
| 156 |
+
" s = 0\n",
|
| 157 |
+
" else:\n",
|
| 158 |
+
" s = (difference / max_rgb) * 100\n",
|
| 159 |
+
" \n",
|
| 160 |
+
" # compute v\n",
|
| 161 |
+
" v = max_rgb * 100\n",
|
| 162 |
+
" # return rounded values of H, S and V\n",
|
| 163 |
+
" return tuple(map(round, (h, s, v)))\n",
|
| 164 |
+
" "
|
| 165 |
+
]
|
| 166 |
+
},
|
| 167 |
+
{
|
| 168 |
+
"cell_type": "code",
|
| 169 |
+
"execution_count": null,
|
| 170 |
+
"metadata": {},
|
| 171 |
+
"outputs": [],
|
| 172 |
+
"source": [
|
| 173 |
+
"def obtain_hsv_colors(img):\n",
|
| 174 |
+
" colors = extcolors.extract_from_path(img, tolerance=7, limit=7)\n",
|
| 175 |
+
" colors = [(rgb2hsv(h[0][0], h[0][1], h[0][2]), h[1]) for h in colors[0] if h[0] != (0,0,0)]\n",
|
| 176 |
+
" return colors"
|
| 177 |
+
]
|
| 178 |
+
},
|
| 179 |
+
{
|
| 180 |
+
"cell_type": "code",
|
| 181 |
+
"execution_count": null,
|
| 182 |
+
"metadata": {},
|
| 183 |
+
"outputs": [],
|
| 184 |
+
"source": [
|
| 185 |
+
"colors = obtain_hsv_colors(images_textiles[0])\n",
|
| 186 |
+
"print(colors)"
|
| 187 |
+
]
|
| 188 |
+
},
|
| 189 |
+
{
|
| 190 |
+
"cell_type": "code",
|
| 191 |
+
"execution_count": null,
|
| 192 |
+
"metadata": {},
|
| 193 |
+
"outputs": [],
|
| 194 |
+
"source": [
|
| 195 |
+
"for col in colors:\n",
|
| 196 |
+
" print(get_color_rank(*col[0]))"
|
| 197 |
+
]
|
| 198 |
+
},
|
| 199 |
+
{
|
| 200 |
+
"cell_type": "code",
|
| 201 |
+
"execution_count": null,
|
| 202 |
+
"metadata": {},
|
| 203 |
+
"outputs": [],
|
| 204 |
+
"source": [
|
| 205 |
+
"for img in images_textiles[:30]:\n",
|
| 206 |
+
" colors = obtain_hsv_colors(img)\n",
|
| 207 |
+
" plt.imshow(plt.imread(img))\n",
|
| 208 |
+
" plt.show()\n",
|
| 209 |
+
" for col in colors:\n",
|
| 210 |
+
" print(col[0])\n",
|
| 211 |
+
" print(get_color_rank(*col[0]))\n",
|
| 212 |
+
" \n",
|
| 213 |
+
" print()"
|
| 214 |
+
]
|
| 215 |
+
},
|
| 216 |
+
{
|
| 217 |
+
"cell_type": "markdown",
|
| 218 |
+
"metadata": {},
|
| 219 |
+
"source": [
|
| 220 |
+
"### use for training only images with medium saturation and value\n",
|
| 221 |
+
"\n",
|
| 222 |
+
"use codes and not only hue for color categorization\n",
|
| 223 |
+
"or remove colors that are creater with black and whites"
|
| 224 |
+
]
|
| 225 |
+
},
|
| 226 |
+
{
|
| 227 |
+
"cell_type": "code",
|
| 228 |
+
"execution_count": null,
|
| 229 |
+
"metadata": {},
|
| 230 |
+
"outputs": [],
|
| 231 |
+
"source": []
|
| 232 |
+
}
|
| 233 |
+
],
|
| 234 |
+
"metadata": {
|
| 235 |
+
"kernelspec": {
|
| 236 |
+
"display_name": "art-reco_x86",
|
| 237 |
+
"language": "python",
|
| 238 |
+
"name": "python3"
|
| 239 |
+
},
|
| 240 |
+
"language_info": {
|
| 241 |
+
"codemirror_mode": {
|
| 242 |
+
"name": "ipython",
|
| 243 |
+
"version": 3
|
| 244 |
+
},
|
| 245 |
+
"file_extension": ".py",
|
| 246 |
+
"mimetype": "text/x-python",
|
| 247 |
+
"name": "python",
|
| 248 |
+
"nbconvert_exporter": "python",
|
| 249 |
+
"pygments_lexer": "ipython3",
|
| 250 |
+
"version": "3.8.16"
|
| 251 |
+
},
|
| 252 |
+
"orig_nbformat": 4
|
| 253 |
+
},
|
| 254 |
+
"nbformat": 4,
|
| 255 |
+
"nbformat_minor": 2
|
| 256 |
+
}
|
interfacegan_colour_disentanglement.ipynb
CHANGED
|
@@ -15,6 +15,7 @@
|
|
| 15 |
"\n",
|
| 16 |
"from PIL import Image, ImageColor\n",
|
| 17 |
"import matplotlib.pyplot as plt\n",
|
|
|
|
| 18 |
"\n",
|
| 19 |
"import numpy as np\n",
|
| 20 |
"import torch\n",
|
|
@@ -33,6 +34,87 @@
|
|
| 33 |
"%autoreload 2"
|
| 34 |
]
|
| 35 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
{
|
| 37 |
"cell_type": "code",
|
| 38 |
"execution_count": null,
|
|
@@ -43,6 +125,21 @@
|
|
| 43 |
"num_colors = 7"
|
| 44 |
]
|
| 45 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
{
|
| 47 |
"cell_type": "code",
|
| 48 |
"execution_count": null,
|
|
@@ -50,8 +147,7 @@
|
|
| 50 |
"metadata": {},
|
| 51 |
"outputs": [],
|
| 52 |
"source": [
|
| 53 |
-
"
|
| 54 |
-
"centers = [int((values[i-1]+values[i])/2) for i in range(len(values)) if i > 0]"
|
| 55 |
]
|
| 56 |
},
|
| 57 |
{
|
|
@@ -61,7 +157,7 @@
|
|
| 61 |
"metadata": {},
|
| 62 |
"outputs": [],
|
| 63 |
"source": [
|
| 64 |
-
"print(
|
| 65 |
"print(centers)"
|
| 66 |
]
|
| 67 |
},
|
|
@@ -100,9 +196,9 @@
|
|
| 100 |
"metadata": {},
|
| 101 |
"outputs": [],
|
| 102 |
"source": [
|
| 103 |
-
"def to_256(val):\n",
|
| 104 |
-
"
|
| 105 |
-
"
|
| 106 |
]
|
| 107 |
},
|
| 108 |
{
|
|
@@ -112,9 +208,7 @@
|
|
| 112 |
"metadata": {},
|
| 113 |
"outputs": [],
|
| 114 |
"source": [
|
| 115 |
-
"names = ['
|
| 116 |
-
" 'Kelly Green', 'Green Blue Seafoam', 'Cyan Blue',\n",
|
| 117 |
-
" 'Warm Blue', 'Indigo', 'Purple Magenta', 'Magenta Pink']"
|
| 118 |
]
|
| 119 |
},
|
| 120 |
{
|
|
@@ -127,7 +221,7 @@
|
|
| 127 |
"saturation = 1 # Saturation value (0 to 1)\n",
|
| 128 |
"value = 1 # Value (brightness) value (0 to 1)\n",
|
| 129 |
"for hue, name in zip(centers, names[:num_colors]):\n",
|
| 130 |
-
" image = create_color_image(
|
| 131 |
" display_image(image, name) # Display the generated color image"
|
| 132 |
]
|
| 133 |
},
|
|
@@ -148,6 +242,37 @@
|
|
| 148 |
" model = legacy.load_network_pkl(f)['G_ema'].to('cpu') # type: ignore\n"
|
| 149 |
]
|
| 150 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
{
|
| 152 |
"cell_type": "code",
|
| 153 |
"execution_count": null,
|
|
@@ -155,7 +280,6 @@
|
|
| 155 |
"metadata": {},
|
| 156 |
"outputs": [],
|
| 157 |
"source": [
|
| 158 |
-
"ann_df = tohsv(ann_df)\n",
|
| 159 |
"ann_df.head()"
|
| 160 |
]
|
| 161 |
},
|
|
@@ -291,9 +415,7 @@
|
|
| 291 |
"metadata": {},
|
| 292 |
"outputs": [],
|
| 293 |
"source": [
|
| 294 |
-
"colors_list =
|
| 295 |
-
" 'Kelly Green', 'Green Blue Seafoam', 'Blue Green Cyan',\n",
|
| 296 |
-
" 'Warm Blue', 'Indigo Blue Purple', 'Purple Magenta', 'Magenta Pink']"
|
| 297 |
]
|
| 298 |
},
|
| 299 |
{
|
|
@@ -313,10 +435,17 @@
|
|
| 313 |
"source": [
|
| 314 |
"from sklearn import svm\n",
|
| 315 |
"\n",
|
| 316 |
-
"
|
| 317 |
-
"y_h_cat = pd.cut(y_h,bins=[x*256/12 if x<12 else 256 for x in range(13)],labels=colors_list).fillna('Warm Pink Red')\n",
|
| 318 |
"\n",
|
| 319 |
"print(y_h_cat.value_counts(dropna=False))\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 320 |
"x_trainhc, x_valhc, y_trainhc, y_valhc = train_test_split(X, y_h_cat, test_size=0.2)"
|
| 321 |
]
|
| 322 |
},
|
|
|
|
| 15 |
"\n",
|
| 16 |
"from PIL import Image, ImageColor\n",
|
| 17 |
"import matplotlib.pyplot as plt\n",
|
| 18 |
+
"from sklearn.model_selection import train_test_split\n",
|
| 19 |
"\n",
|
| 20 |
"import numpy as np\n",
|
| 21 |
"import torch\n",
|
|
|
|
| 34 |
"%autoreload 2"
|
| 35 |
]
|
| 36 |
},
|
| 37 |
+
{
|
| 38 |
+
"cell_type": "markdown",
|
| 39 |
+
"id": "03efb8c0",
|
| 40 |
+
"metadata": {},
|
| 41 |
+
"source": [
|
| 42 |
+
"0-60\n",
|
| 43 |
+
"\n",
|
| 44 |
+
"Red\n",
|
| 45 |
+
"\n",
|
| 46 |
+
"60-120\n",
|
| 47 |
+
"\n",
|
| 48 |
+
"Yellow\n",
|
| 49 |
+
"\n",
|
| 50 |
+
"120-180\n",
|
| 51 |
+
"\n",
|
| 52 |
+
"Green\n",
|
| 53 |
+
"\n",
|
| 54 |
+
"180-240\n",
|
| 55 |
+
"\n",
|
| 56 |
+
"Cyan\n",
|
| 57 |
+
"\n",
|
| 58 |
+
"240-300\n",
|
| 59 |
+
"\n",
|
| 60 |
+
"Blue\n",
|
| 61 |
+
"\n",
|
| 62 |
+
"300-360\n",
|
| 63 |
+
"\n",
|
| 64 |
+
"Magenta\n",
|
| 65 |
+
"\n",
|
| 66 |
+
"Standard classification"
|
| 67 |
+
]
|
| 68 |
+
},
|
| 69 |
+
{
|
| 70 |
+
"cell_type": "code",
|
| 71 |
+
"execution_count": null,
|
| 72 |
+
"id": "00a35126",
|
| 73 |
+
"metadata": {},
|
| 74 |
+
"outputs": [],
|
| 75 |
+
"source": [
|
| 76 |
+
"def hex2rgb(hex_value):\n",
|
| 77 |
+
" h = hex_value.strip(\"#\") \n",
|
| 78 |
+
" rgb = tuple(int(h[i:i+2], 16) for i in (0, 2, 4))\n",
|
| 79 |
+
" return rgb\n",
|
| 80 |
+
"\n",
|
| 81 |
+
"def rgb2hsv(r, g, b):\n",
|
| 82 |
+
" # Normalize R, G, B values\n",
|
| 83 |
+
" r, g, b = r / 255.0, g / 255.0, b / 255.0\n",
|
| 84 |
+
" \n",
|
| 85 |
+
" # h, s, v = hue, saturation, value\n",
|
| 86 |
+
" max_rgb = max(r, g, b) \n",
|
| 87 |
+
" min_rgb = min(r, g, b) \n",
|
| 88 |
+
" difference = max_rgb-min_rgb \n",
|
| 89 |
+
" \n",
|
| 90 |
+
" # if max_rgb and max_rgb are equal then h = 0\n",
|
| 91 |
+
" if max_rgb == min_rgb:\n",
|
| 92 |
+
" h = 0\n",
|
| 93 |
+
" \n",
|
| 94 |
+
" # if max_rgb==r then h is computed as follows\n",
|
| 95 |
+
" elif max_rgb == r:\n",
|
| 96 |
+
" h = (60 * ((g - b) / difference) + 360) % 360\n",
|
| 97 |
+
" \n",
|
| 98 |
+
" # if max_rgb==g then compute h as follows\n",
|
| 99 |
+
" elif max_rgb == g:\n",
|
| 100 |
+
" h = (60 * ((b - r) / difference) + 120) % 360\n",
|
| 101 |
+
" \n",
|
| 102 |
+
" # if max_rgb=b then compute h\n",
|
| 103 |
+
" elif max_rgb == b:\n",
|
| 104 |
+
" h = (60 * ((r - g) / difference) + 240) % 360\n",
|
| 105 |
+
" \n",
|
| 106 |
+
" # if max_rgb==zero then s=0\n",
|
| 107 |
+
" if max_rgb == 0:\n",
|
| 108 |
+
" s = 0\n",
|
| 109 |
+
" else:\n",
|
| 110 |
+
" s = (difference / max_rgb) * 100\n",
|
| 111 |
+
" \n",
|
| 112 |
+
" # compute v\n",
|
| 113 |
+
" v = max_rgb * 100\n",
|
| 114 |
+
" # return rounded values of H, S and V\n",
|
| 115 |
+
" return tuple(map(round, (h, s, v)))"
|
| 116 |
+
]
|
| 117 |
+
},
|
| 118 |
{
|
| 119 |
"cell_type": "code",
|
| 120 |
"execution_count": null,
|
|
|
|
| 125 |
"num_colors = 7"
|
| 126 |
]
|
| 127 |
},
|
| 128 |
+
{
|
| 129 |
+
"cell_type": "code",
|
| 130 |
+
"execution_count": null,
|
| 131 |
+
"id": "c8428918",
|
| 132 |
+
"metadata": {},
|
| 133 |
+
"outputs": [],
|
| 134 |
+
"source": [
|
| 135 |
+
"bins = [(x-1) * 360 / (num_colors - 1) if x != 1 \n",
|
| 136 |
+
" else 1 for x in range(num_colors + 1)]\n",
|
| 137 |
+
"bins[0] = 0\n",
|
| 138 |
+
"\n",
|
| 139 |
+
"bins\n",
|
| 140 |
+
" "
|
| 141 |
+
]
|
| 142 |
+
},
|
| 143 |
{
|
| 144 |
"cell_type": "code",
|
| 145 |
"execution_count": null,
|
|
|
|
| 147 |
"metadata": {},
|
| 148 |
"outputs": [],
|
| 149 |
"source": [
|
| 150 |
+
"centers = [int((bins[i-1]+bins[i])/2) for i in range(len(bins)) if i > 0]"
|
|
|
|
| 151 |
]
|
| 152 |
},
|
| 153 |
{
|
|
|
|
| 157 |
"metadata": {},
|
| 158 |
"outputs": [],
|
| 159 |
"source": [
|
| 160 |
+
"print(bins)\n",
|
| 161 |
"print(centers)"
|
| 162 |
]
|
| 163 |
},
|
|
|
|
| 196 |
"metadata": {},
|
| 197 |
"outputs": [],
|
| 198 |
"source": [
|
| 199 |
+
"# def to_256(val):\n",
|
| 200 |
+
"# x = val*360/256\n",
|
| 201 |
+
"# return int(x)"
|
| 202 |
]
|
| 203 |
},
|
| 204 |
{
|
|
|
|
| 208 |
"metadata": {},
|
| 209 |
"outputs": [],
|
| 210 |
"source": [
|
| 211 |
+
"names = ['Gray', 'Red', 'Yellow', 'Green', 'Cyan', 'Blue','Magenta']"
|
|
|
|
|
|
|
| 212 |
]
|
| 213 |
},
|
| 214 |
{
|
|
|
|
| 221 |
"saturation = 1 # Saturation value (0 to 1)\n",
|
| 222 |
"value = 1 # Value (brightness) value (0 to 1)\n",
|
| 223 |
"for hue, name in zip(centers, names[:num_colors]):\n",
|
| 224 |
+
" image = create_color_image(hue, saturation, value)\n",
|
| 225 |
" display_image(image, name) # Display the generated color image"
|
| 226 |
]
|
| 227 |
},
|
|
|
|
| 242 |
" model = legacy.load_network_pkl(f)['G_ema'].to('cpu') # type: ignore\n"
|
| 243 |
]
|
| 244 |
},
|
| 245 |
+
{
|
| 246 |
+
"cell_type": "code",
|
| 247 |
+
"execution_count": null,
|
| 248 |
+
"id": "065cd656",
|
| 249 |
+
"metadata": {},
|
| 250 |
+
"outputs": [],
|
| 251 |
+
"source": [
|
| 252 |
+
"from DisentanglementBase import DisentanglementBase"
|
| 253 |
+
]
|
| 254 |
+
},
|
| 255 |
+
{
|
| 256 |
+
"cell_type": "code",
|
| 257 |
+
"execution_count": null,
|
| 258 |
+
"id": "afb8a611",
|
| 259 |
+
"metadata": {},
|
| 260 |
+
"outputs": [],
|
| 261 |
+
"source": [
|
| 262 |
+
"variable = 'H1'\n",
|
| 263 |
+
"disentanglemnet_exp = DisentanglementBase('.', model, annotations, ann_df, space='W', colors_list=names, compute_s=False, variable=variable)\n"
|
| 264 |
+
]
|
| 265 |
+
},
|
| 266 |
+
{
|
| 267 |
+
"cell_type": "code",
|
| 268 |
+
"execution_count": null,
|
| 269 |
+
"id": "a7398217",
|
| 270 |
+
"metadata": {},
|
| 271 |
+
"outputs": [],
|
| 272 |
+
"source": [
|
| 273 |
+
"ann_df = disentanglemnet_exp.df"
|
| 274 |
+
]
|
| 275 |
+
},
|
| 276 |
{
|
| 277 |
"cell_type": "code",
|
| 278 |
"execution_count": null,
|
|
|
|
| 280 |
"metadata": {},
|
| 281 |
"outputs": [],
|
| 282 |
"source": [
|
|
|
|
| 283 |
"ann_df.head()"
|
| 284 |
]
|
| 285 |
},
|
|
|
|
| 415 |
"metadata": {},
|
| 416 |
"outputs": [],
|
| 417 |
"source": [
|
| 418 |
+
"colors_list = names"
|
|
|
|
|
|
|
| 419 |
]
|
| 420 |
},
|
| 421 |
{
|
|
|
|
| 435 |
"source": [
|
| 436 |
"from sklearn import svm\n",
|
| 437 |
"\n",
|
| 438 |
+
"y_h_cat = pd.cut(y_h,bins=bins,labels=colors_list, include_lowest=True)\n",
|
|
|
|
| 439 |
"\n",
|
| 440 |
"print(y_h_cat.value_counts(dropna=False))\n",
|
| 441 |
+
"\n",
|
| 442 |
+
"y_h_cat[y_s == 0] = 'Gray'\n",
|
| 443 |
+
"y_h_cat[y_s == 100] = 'Gray'\n",
|
| 444 |
+
"y_h_cat[y_v == 0] = 'Gray'\n",
|
| 445 |
+
"y_h_cat[y_v == 100] = 'Gray'\n",
|
| 446 |
+
"\n",
|
| 447 |
+
"print(y_h_cat.value_counts(dropna=False))\n",
|
| 448 |
+
"\n",
|
| 449 |
"x_trainhc, x_valhc, y_trainhc, y_valhc = train_test_split(X, y_h_cat, test_size=0.2)"
|
| 450 |
]
|
| 451 |
},
|
structure_annotations.ipynb
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|