(model_path)
| 217 | |
| 218 | |
| 219 | def sample(model_path): |
| 220 | pred = OfflinePredictor(PredictConfig( |
| 221 | session_init=SmartInit(model_path), |
| 222 | model=Model(), |
| 223 | input_names=['z_code', 'z_noise'], |
| 224 | output_names=['gen/viz'])) |
| 225 | |
| 226 | # sample all one-hot encodings (10 times) |
| 227 | z_cat = np.tile(np.eye(10), [10, 1]) |
| 228 | # sample continuos variables from -2 to +2 as mentioned in the paper |
| 229 | z_uni = np.linspace(-2.0, 2.0, num=100) |
| 230 | z_uni = z_uni[:, None] |
| 231 | |
| 232 | IMG_SIZE = 400 |
| 233 | |
| 234 | while True: |
| 235 | # only categorical turned on |
| 236 | z_noise = np.random.uniform(-1, 1, (100, NOISE_DIM)) |
| 237 | zc = np.concatenate((z_cat, z_uni * 0, z_uni * 0), axis=1) |
| 238 | o = pred(zc, z_noise)[0] |
| 239 | viz1 = viz.stack_patches(o, nr_row=10, nr_col=10) |
| 240 | viz1 = cv2.resize(viz1, (IMG_SIZE, IMG_SIZE)) |
| 241 | |
| 242 | # show effect of first continous variable with fixed noise |
| 243 | zc = np.concatenate((z_cat, z_uni, z_uni * 0), axis=1) |
| 244 | o = pred(zc, z_noise * 0)[0] |
| 245 | viz2 = viz.stack_patches(o, nr_row=10, nr_col=10) |
| 246 | viz2 = cv2.resize(viz2, (IMG_SIZE, IMG_SIZE)) |
| 247 | |
| 248 | # show effect of second continous variable with fixed noise |
| 249 | zc = np.concatenate((z_cat, z_uni * 0, z_uni), axis=1) |
| 250 | o = pred(zc, z_noise * 0)[0] |
| 251 | viz3 = viz.stack_patches(o, nr_row=10, nr_col=10) |
| 252 | viz3 = cv2.resize(viz3, (IMG_SIZE, IMG_SIZE)) |
| 253 | |
| 254 | canvas = viz.stack_patches( |
| 255 | [viz1, viz2, viz3], |
| 256 | nr_row=1, nr_col=3, border=5, bgcolor=(255, 0, 0)) |
| 257 | |
| 258 | viz.interactive_imshow(canvas) |
| 259 | |
| 260 | |
| 261 | if __name__ == '__main__': |
no test coverage detected
searching dependent graphs…