In [1]:
from scipy.misc import imsave, toimage
from os import listdir
from os.path import basename, splitext
import glob
import numpy as np
npy_path = '../compressed-models/alexnet/npy/'
jpg_path = '../compressed-models/alexnet/jpegs/'
gif_path = '../compressed-models/alexnet/gifs/'
png_path = '../compressed-models/alexnet/pngs/'
txt_path = '../compressed-models/alexnet/txts/'
In [5]:
npy_list = glob.glob(npy_path + '*.npy')
min_max = {}
for file in npy_list:
f = np.load(file)
x = f.shape[0]
y = np.prod(f.shape[1:])
f_reshape = f.reshape(x, y)
#f_normalized = np.round((f_reshape + 1) / 2. * 255.)
filename = splitext(basename(file))[0]
#toimage(jpg_path + filename + '.jpg', f_resha)
min_max[filename] = (f_reshape.min(), f_reshape.max())
np.savetxt(txt_path + filename + '.txt', f_reshape)
#np.save(jpg_path + 'range.npy', min_max)
Load all npys and convert them to JPEG
In [ ]:
npy_list = glob.glob(npy_path + '*.npy')
min_max = {}
for file in npy_list:
f = np.load(file)
x = f.shape[0]
y = np.prod(f.shape[1:])
f_reshape = f.reshape(x, y)
#f_normalized = np.round((f_reshape + 1) / 2. * 255.)
filename = splitext(basename(file))[0]
#toimage(jpg_path + filename + '.jpg', f_resha)
min_max[filename] = (f_reshape.min(), f_reshape.max())
imsave(jpg_path + filename + '.jpg', f_reshape)
np.save(jpg_path + 'range.npy', min_max)
Load all npys and convert them to GIF
In [ ]:
npy_list = glob.glob(npy_path + '*.npy')
min_max = {}
for file in npy_list:
f = np.load(file)
x = f.shape[0]
y = np.prod(f.shape[1:])
f_reshape = f.reshape(x, y)
#f_normalized = np.round((f_reshape + 1) / 2. * 255.)
filename = splitext(basename(file))[0]
#toimage(jpg_path + filename + '.jpg', f_resha)
min_max[filename] = (f_reshape.min(), f_reshape.max())
imsave(gif_path + filename + '.gif', f_reshape)
np.save(gif_path + 'range.npy', min_max)
Load all npys and convert them to PNG
In [ ]:
npy_list = glob.glob(npy_path + '*.npy')
min_max = {}
for file in npy_list:
f = np.load(file)
x = f.shape[0]
y = np.prod(f.shape[1:])
f_reshape = f.reshape(x, y)
#f_normalized = np.round((f_reshape + 1) / 2. * 255.)
filename = splitext(basename(file))[0]
#toimage(jpg_path + filename + '.jpg', f_resha)
min_max[filename] = (f_reshape.min(), f_reshape.max())
imsave(png_path + filename + '.png', f_reshape)
np.save(png_path + 'range.npy', min_max)
In [ ]:
from scipy.misc import imread
f = imread(jpg_path + 'conv1.jpg')
min_max = np.load('range.npy')
#f_normalized = (f / 255. * 2.) - 1
print f[0]
print min_max