def call_plot(model_dict, data_dict, info): from acn_utils import tsne_plot from acn_utils import pca_plot # always be in eval mode model_dict = set_model_mode(model_dict, 'valid') with torch.no_grad(): for phase in ['valid', 'train']: data_loader = data_dict[phase] data_loader.reset_unique() batch = data_loader.get_unique_minibatch(84) states, actions, rewards, next_states, _, _, batch_indexes, index_indexes = batch fp_out = forward_pass(model_dict, states, actions, rewards, next_states, index_indexes, phase, info) model_dict, states, actions, rewards, target, u_q, u_p, s_p, rec_dml, pcnn_dml, z_e_x, z_q_x, latents = fp_out bs = states.shape[0] u_q_flat = u_q.view(bs, info['code_length']) X = u_q_flat.cpu().numpy() color = index_indexes images = target[:,0].cpu().numpy() if args.tsne: param_name = '_tsne_%s_P%s.html'%(phase, info['perplexity']) html_path = info['model_loadpath'].replace('.pt', param_name) tsne_plot(X=X, images=images, color=color, perplexity=info['perplexity'], html_out_path=html_path, serve=False) if args.pca: param_name = '_pca_%s.html'%(phase) html_path = info['model_loadpath'].replace('.pt', param_name) pca_plot(X=X, images=images, color=color, html_out_path=html_path, serve=False) break
def call_plot(model_dict, data_dict, info, sample, tsne, pca): from acn_utils import tsne_plot from acn_utils import pca_plot # always be in eval mode - so we dont swap neighbors model_dict = set_model_mode(model_dict, 'valid') with torch.no_grad(): for phase in ['valid', 'train']: data_loader = data_dict[phase] data_loader.reset_unique() batch = data_loader.get_unique_minibatch(84) states, actions, rewards, next_states, _, _, batch_indexes, index_indexes = batch fp_out = forward_pass(model_dict, states, actions, rewards, next_states, index_indexes, phase, info) model_dict, states, actions, rewards, target, u_q, u_p, s_p, rec_dml, z_e_x, z_q_x, latents = fp_out rec_yhat = sample_from_discretized_mix_logistic( rec_dml, info['nr_logistic_mix'], only_mean=info['sample_mean'], sampling_temperature=info['sampling_temperature']) f, ax = plt.subplots(10, 3) ax[0, 0].set_title('prev') ax[0, 1].set_title('true') ax[0, 2].set_title('pred') for i in range(10): ax[i, 0].matshow(states[i, -1]) ax[i, 1].matshow(target[i, -1]) ax[i, 2].matshow(rec_yhat[i, -1]) ax[i, 0].axis('off') ax[i, 1].axis('off') ax[i, 2].axis('off') plt.subplots_adjust(wspace=0, hspace=0) plt.tight_layout() plt_path = info['model_loadpath'].replace('.pt', '_%s_plt.png' % phase) print('plotting', plt_path) plt.savefig(plt_path) bs = states.shape[0] u_q_flat = u_q.view(bs, info['code_length']) X = u_q_flat.cpu().numpy() color = index_indexes images = target[:, 0].cpu().numpy() if tsne: param_name = '_tsne_%s_P%s.html' % (phase, info['perplexity']) html_path = info['model_loadpath'].replace('.pt', param_name) tsne_plot(X=X, images=images, color=color, perplexity=info['perplexity'], html_out_path=html_path, serve=False) if pca: param_name = '_pca_%s.html' % (phase) html_path = info['model_loadpath'].replace('.pt', param_name) pca_plot(X=X, images=images, color=color, html_out_path=html_path, serve=False)