def vis_square(data): """ Code from: http://nbviewer.jupyter.org/github/BVLC/caffe/blob/master/examples/00-classification.ipynb, with small modifications Take an array of shape (n, height, width) or (n, height, width, 3) and visualize each (height, width) thing in a grid of size approx. sqrt(n) by sqrt(n) """ # normalize data for display data = (data - data.min()) / (data.max() - data.min()) # force the number of filters to be square n = int(np.ceil(np.sqrt(data.shape[0]))) padding = (((0, n**2 - data.shape[0]), (0, 1), (0, 1)) + ((0, 0), ) * (data.ndim - 3) ) # don't pad the last dimension (if there is one) data = np.pad(data, padding, mode='constant', constant_values=1) # pad with ones (white) # tile the filters into an image data = data.reshape((n, n) + data.shape[1:]).transpose( (0, 2, 1, 3) + tuple(range(4, data.ndim + 1))) data = data.reshape((n * data.shape[1], n * data.shape[3]) + data.shape[4:]) fig = plt.figure(figsize=(10, 10)) ax = fig.add_subplot(111) with plt.rc_context({ 'image.interpolation': 'nearest', 'image.cmap': 'gray' }): ax.imshow(data) ax.axis('off') return fig
def show_training_matrixes(estimates, title): length = len(estimates) axes = [] fig = plt.figure(figsize=(100, 2 * length)) fig.suptitle(title, fontsize=30, verticalalignment='top') for i in range(length): axes.append(fig.add_subplot(length, 1, i + 1)) with plt.rc_context({'image.cmap': 'gray', 'image.interpolation': 'nearest'}): for i in range(length): axes[i].matshow(estimates[i]) axes[i].axis('off') return fig
# %tensorflow_version 2.x import tensorflow as tf import tensorflow_hub as hub from tensorflow.keras.preprocessing.text import Tokenizer from tensorflow.keras.preprocessing.sequence import pad_sequences from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense, Embedding, Flatten, GlobalAveragePooling1D import numpy as np import pandas as pd import matplotlib.pylab as plt import os, re, json, functools plt.rc_context({'xtick.color':'w', 'ytick.color':'w', 'text.color':'w', 'axes.labelcolor':'w'}) seed=2811 np.random.seed(seed) tf.random.set_seed(seed) pip install kaggle --upgrade os.environ['KAGGLE_USERNAME'] = "******" os.environ['KAGGLE_KEY'] = "5912caabf0d1fa350842f382da374953" #https://www.kaggle.com/rounakbanik/the-movies-dataset !kaggle datasets download rounakbanik/the-movies-dataset !unzip -o 'the-movies-dataset.zip'
#code used to plot a graph from matplotlib import pylab as plt get_ipython().magic('matplotlib inline') # tweak figure appearance rc = {'xtick.labelsize': 16, 'ytick.labelsize': 16, 'axes.labelsize': 18, 'axes.labelweight': '900', 'legend.fontsize': 20, 'font.family': 'cursive', 'font.monospace': 'Nimbus Mono L', 'lines.linewidth': 2, 'lines.markersize': 9, 'xtick.major.pad': 20} plt.rc_context(rc=rc) plt.rcParams['font.family'] = 'serif' plt.rcParams['axes.labelsize'] = 22 plt.rcParams['figure.figsize'] = 9, 6 # make figures larger in notebook def plot_results(results, title, xlabels, ylabel="Success Rate"): '''Plot a bar graph of results''' ind = np.arange(len(results)) width = 0.4 plt.bar(ind, results, width, color="#1AADA4") plt.ylabel(ylabel) plt.ylim(ymax=100) plt.xticks(ind+width/2.0, xlabels) plt.title(title)