(sess, dcgan, config, option, sample_dir='samples')
| 188 | clip.write_gif(fname, fps = len(images) / duration) |
| 189 | |
| 190 | def visualize(sess, dcgan, config, option, sample_dir='samples'): |
| 191 | image_frame_dim = int(math.ceil(config.batch_size**.5)) |
| 192 | if option == 0: |
| 193 | z_sample = np.random.uniform(-0.5, 0.5, size=(config.batch_size, dcgan.z_dim)) |
| 194 | samples = sess.run(dcgan.sampler, feed_dict={dcgan.z: z_sample}) |
| 195 | save_images(samples, [image_frame_dim, image_frame_dim], os.path.join(sample_dir, 'test_%s.png' % strftime("%Y%m%d%H%M%S", gmtime() ))) |
| 196 | elif option == 1: |
| 197 | values = np.arange(0, 1, 1./config.batch_size) |
| 198 | for idx in xrange(dcgan.z_dim): |
| 199 | print(" [*] %d" % idx) |
| 200 | z_sample = np.random.uniform(-1, 1, size=(config.batch_size , dcgan.z_dim)) |
| 201 | for kdx, z in enumerate(z_sample): |
| 202 | z[idx] = values[kdx] |
| 203 | |
| 204 | if config.dataset == "mnist": |
| 205 | y = np.random.choice(10, config.batch_size) |
| 206 | y_one_hot = np.zeros((config.batch_size, 10)) |
| 207 | y_one_hot[np.arange(config.batch_size), y] = 1 |
| 208 | |
| 209 | samples = sess.run(dcgan.sampler, feed_dict={dcgan.z: z_sample, dcgan.y: y_one_hot}) |
| 210 | else: |
| 211 | samples = sess.run(dcgan.sampler, feed_dict={dcgan.z: z_sample}) |
| 212 | |
| 213 | save_images(samples, [image_frame_dim, image_frame_dim], os.path.join(sample_dir, 'test_arange_%s.png' % (idx))) |
| 214 | elif option == 2: |
| 215 | values = np.arange(0, 1, 1./config.batch_size) |
| 216 | for idx in [random.randint(0, dcgan.z_dim - 1) for _ in xrange(dcgan.z_dim)]: |
| 217 | print(" [*] %d" % idx) |
| 218 | z = np.random.uniform(-0.2, 0.2, size=(dcgan.z_dim)) |
| 219 | z_sample = np.tile(z, (config.batch_size, 1)) |
| 220 | #z_sample = np.zeros([config.batch_size, dcgan.z_dim]) |
| 221 | for kdx, z in enumerate(z_sample): |
| 222 | z[idx] = values[kdx] |
| 223 | |
| 224 | if config.dataset == "mnist": |
| 225 | y = np.random.choice(10, config.batch_size) |
| 226 | y_one_hot = np.zeros((config.batch_size, 10)) |
| 227 | y_one_hot[np.arange(config.batch_size), y] = 1 |
| 228 | |
| 229 | samples = sess.run(dcgan.sampler, feed_dict={dcgan.z: z_sample, dcgan.y: y_one_hot}) |
| 230 | else: |
| 231 | samples = sess.run(dcgan.sampler, feed_dict={dcgan.z: z_sample}) |
| 232 | |
| 233 | try: |
| 234 | make_gif(samples, './samples/test_gif_%s.gif' % (idx)) |
| 235 | except: |
| 236 | save_images(samples, [image_frame_dim, image_frame_dim], os.path.join(sample_dir, 'test_%s.png' % strftime("%Y%m%d%H%M%S", gmtime() ))) |
| 237 | elif option == 3: |
| 238 | values = np.arange(0, 1, 1./config.batch_size) |
| 239 | for idx in xrange(dcgan.z_dim): |
| 240 | print(" [*] %d" % idx) |
| 241 | z_sample = np.zeros([config.batch_size, dcgan.z_dim]) |
| 242 | for kdx, z in enumerate(z_sample): |
| 243 | z[idx] = values[kdx] |
| 244 | |
| 245 | samples = sess.run(dcgan.sampler, feed_dict={dcgan.z: z_sample}) |
| 246 | make_gif(samples, os.path.join(sample_dir, 'test_gif_%s.gif' % (idx))) |
| 247 | elif option == 4: |
no test coverage detected