<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 1. Converting Parameters to JPEG
Step1:  Load all npys and convert them to JPEG
Step2:  Load all npys and convert them to GIF
Step3:  Load all npys and convert them to PNG
Step4:  2. Reference Sizes
<ASSISTANT_TASK:>
Python Code:
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/'
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)
Explanation: 1. Converting Parameters to JPEG
End of explanation
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)
Explanation: Load all npys and convert them to JPEG
End of explanation
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)
Explanation: Load all npys and convert them to GIF
End of explanation
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)
Explanation: Load all npys and convert them to PNG
End of explanation
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
Explanation: 2. Reference Sizes:
conv1 (96, 3, 11, 11) (96,)
conv2 (256, 48, 5, 5) (256,)
conv3 (384, 256, 3, 3) (384,)
conv4 (384, 192, 3, 3) (384,)
conv5 (256, 192, 3, 3) (256,)
fc6 (4096, 9216) (4096,)
fc7 (4096, 4096) (4096,)
fc8 (1000, 4096) (1000,)
3. Sanity Check
End of explanation
<END_TASK>