Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
def show_image_compression(samples): | |
#get encoded samples offloaded to edge | |
_, offload_end = device_models['end'].predict(samples) | |
#get encoded samples offloaded to cloud | |
_, offload_edge = device_models['edge'].predict(offload_end) | |
#show sample represenations at each device level | |
for i in range(len(samples)): | |
print(i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from scipy.special import softmax | |
def get_results(confidence_threshold): | |
print('confidence threshold:',confidence_threshold) | |
predictions = [] | |
confidence = [] | |
exit_level = [] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tensorflow.keras.callbacks import EarlyStopping | |
early_stop = EarlyStopping( | |
monitor='val_loss', min_delta=0, patience=5, verbose=0, mode='auto', | |
baseline=None, restore_best_weights=True) | |
model.fit(x_train, {device:y_train for device in device_names}, | |
batch_size=64, | |
epochs=1000, | |
verbose=1, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
outputs = {} | |
#complete model input | |
inputs = Input(shape=x_train.shape[1:]) | |
net = {'offload':inputs} | |
#stack all 3 device models together | |
for device in device_names: | |
net = device_models[device](net['offload']) | |
outputs[device] = net[device+'_outputs'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tensorflow.keras.models import Model | |
from tensorflow.keras.layers import Input, Conv2D, Dense, GlobalAvgPool2D, GlobalMaxPool2D, Concatenate, BatchNormalization | |
from tensorflow.keras.losses import SparseCategoricalCrossentropy | |
#function compiling device model | |
def compile_device_model(input_shape=None,n_filters=None,name=None,offload=False): | |
outputs = {} | |
inputs = Input(shape=input_shape) | |
net = inputs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tensorflow.keras.datasets import mnist | |
#load mnist data | |
(x_train,y_train),(x_test,y_test) = mnist.load_data() | |
#reshape and scale input image data | |
x_train, x_test = (x.reshape(*x.shape,1)/x.max() for x in (x_train,x_test)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#function for building classifier (very similar to the discriminator) | |
def compile_classifier(): | |
inputs = {} | |
numeric_nets = [] | |
string_nets = [] | |
for name in numeric_data: | |
numeric_input = Input(shape=(1,),name=name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
import matplotlib.pyplot as plt | |
def train_gan(n_epochs,n_batch,n_plot,n_eval): | |
#discriminator/generator training logs | |
disc_loss_hist = [] | |
gen_loss_hist = [] | |
for epoch in range(n_epochs): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tensorflow.keras.utils import to_categorical | |
#function for generating latent samples for synthetic data for generator training | |
def generate_latent_samples(n): | |
#generate latent vectors with balanced targets | |
x = {'latent': np.random.normal(size=(n, latent_dim)), | |
'target': to_categorical(np.hstack([np.array([_x for _ in range(n//2)]) for _x in range(2)]),2)} | |
#outputs indicating postive discirmination (target value) |
NewerOlder