Spaces:
Runtime error
Runtime error
File size: 4,282 Bytes
52bd88d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "3722712c",
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline \n",
"\n",
"import pandas as pd\n",
"import pickle\n",
"import random\n",
"\n",
"from PIL import Image, ImageColor\n",
"import matplotlib.pyplot as plt\n",
"\n",
"import numpy as np\n",
"import torch\n",
"\n",
"from backend.disentangle_concepts import *\n",
"import dnnlib \n",
"import legacy\n",
"from backend.color_annotations import *\n",
"\n",
"import random\n",
"\n",
"from sklearn.linear_model import LinearRegression, LogisticRegression\n",
"\n",
"\n",
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fe7acfaf-dc61-4211-9c78-8e4433bc9deb",
"metadata": {},
"outputs": [],
"source": [
"annotations_file = './data/textile_annotated_files/seeds0000-100000.pkl'\n",
"with open(annotations_file, 'rb') as f:\n",
" annotations = pickle.load(f)\n",
"\n",
"ann_df = pd.read_csv('./data/textile_annotated_files/top_three_colours.csv').fillna('#000000')\n",
"\n",
"with dnnlib.util.open_url('./data/textile_model_files/network-snapshot-005000.pkl') as f:\n",
" model = legacy.load_network_pkl(f)['G_ema'].to('cpu') # type: ignore\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cd114cb1",
"metadata": {},
"outputs": [],
"source": [
"ann_df = tohsv(ann_df)\n",
"ann_df.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "feb64168",
"metadata": {},
"outputs": [],
"source": [
"X = np.array(annotations['w_vectors']).reshape((len(annotations['w_vectors']), 512))\n",
"print(X.shape)\n",
"y_h = np.array(ann_df['H1'].values)\n",
"y_s = np.array(ann_df['S1'].values)\n",
"y_v = np.array(ann_df['S1'].values)"
]
},
{
"cell_type": "markdown",
"id": "4e814959",
"metadata": {},
"source": [
"### Unsupervised approaches"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c9493f54",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.decomposition import PCA"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "93596853",
"metadata": {},
"outputs": [],
"source": [
"pca = PCA(n_components=20)\n",
"\n",
"dims_pca = pca.fit_transform(x_trainhc.T)\n",
"dims_pca /= np.linalg.norm(dims_pca, axis=0)\n",
"print(dims_pca.shape, np.linalg.norm(dims_pca, axis=0).shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dd0b1501",
"metadata": {},
"outputs": [],
"source": [
"method = 'PCA dimension'\n",
"for sep, num in zip(dims_pca.T, range(10)):\n",
" images, lambdas = regenerate_images(model, original_image_vec, sep, min_epsilon=-(int(4)), max_epsilon=int(4), count=5, latent_space='W')\n",
" fig, axs = plt.subplots(1, len(images), figsize=(50,10))\n",
" fig.suptitle(method +': ' + str(num), fontsize=20)\n",
" for i,im in enumerate(images):\n",
" axs[i].imshow(im)\n",
" axs[i].set_title(np.round(lambdas[i], 2))\n",
" plt.show()"
]
},
{
"cell_type": "markdown",
"id": "4e0c7808",
"metadata": {},
"source": [
"## dimensionality reduction e vediamo dove finiscono i vari colori"
]
},
{
"cell_type": "markdown",
"id": "833ed31f",
"metadata": {},
"source": [
"## clustering per vedere quali sono i centroid di questo spazio e se ci sono regioni determinate dai colori"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7c19e820",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.16"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|