def sample_replay_for_update(self): for i in range(self.state_space_parameters.replay_number): net = np.random.choice(self.replay_dictionary['net']) ''' Uncomment for training ''' # accuracy_best_val = self.replay_dictionary[self.replay_dictionary['net'] == net]['accuracy_best_val'].values[0] # accuracy_last_val = self.replay_dictionary[self.replay_dictionary['net'] == net]['accuracy_last_val'].values[0] # train_flag = self.replay_dictionary[self.replay_dictionary['net'] == net]['train_flag'].values[0] ''' Uncommenting ends ''' loss_inverse = self.replay_dictionary[ self.replay_dictionary['net'] == net]['loss_inverse'].values[0] loss = self.replay_dictionary[self.replay_dictionary['net'] == net]['loss'].values[0] computeLoss_flag = self.replay_dictionary[ self.replay_dictionary['net'] == net]['computeLoss_flag'].values[0] state_list = self.stringutils.convert_model_string_to_states( cnn.parse('net', net)) # print('During update:') # for state in state_list: # print('{} {} {} {} {} {} {} {}'.format(state.layer_type,state.layer_depth, state.filter_depth,\ # state.filter_size, state.stride, state.image_size, state.fc_size, state.terminate)) # print(state_list) ''' Uncomment while training ''' # state_list = self.stringutils.remove_drop_out_states(state_list) ''' Uncommenting ends ''' # state_list = [self.enum.bucket_state(state) for state in state_list] ''' Uncomment while training ''' # if train_flag == True: # self.update_q_value_sequence(state_list, self.accuracy_to_reward(accuracy_best_val)) ''' Uncommenting ends ''' if computeLoss_flag == True: self.update_q_value_sequence( state_list, self.accuracy_to_reward(loss_inverse))
def main(_): _model = __import__( 'models.' + 'cifar10', #args.model, globals(), locals(), ['state_space_parameters', 'hyper_parameters'], -1) ########### Benchmark end-to-end network ########## net_list = cnn.parse('net', args.net_string) StateStringUtils( _model.state_space_parameters).convert_model_string_to_states(net_list)
def sample_replay_for_update_in_latency(self): # Experience replay to update Q-Values for i in range(self.state_space_parameters.replay_number): net = np.random.choice(self.replay_dictionary['net']) latency = self.replay_dictionary[self.replay_dictionary['net'] == net]['latency'].values[0] state_list = self.stringutils.convert_model_string_to_states( cnn.parse('net', net)) state_list = self.stringutils.remove_drop_out_states(state_list) # Convert States so they are bucketed state_list = [ self.enum.bucket_state(state) for state in state_list ] self.update_q_value_sequence( state_list, self.accuracy_to_reward_in_latency(latency))
to_state = State( state_list=gen.qstore.q[start_state.as_tuple()]['to_states'][0]) gen.qstore.q = enum.enumerate_state(to_state, gen.qstore.q) gen.qstore.q[to_state.as_tuple()]['utilities'][0] = 0.6 gen._update_q_value(start_state, to_state, 0.4) assert (gen.qstore.q[start_state.as_tuple()]['utilities'][0] == 0.5 + gen.learning_rate * (0.4 + 0.6 - 0.5)) for i in range(100): previous_action_values = gen.qstore.q.copy() net, acc_best_val, acc_last_val, acc_best_test, acc_last_test = gen.generate_net( ) stringutils = StateStringUtils(state_space_parameters) print net net_lists = cnn.parse('net', net) print '---------------------' print 'Net String' print net print '----------------------' assert (net == stringutils.state_list_to_string( stringutils.convert_model_string_to_states(net_lists))) for key in previous_action_values.keys(): old_to_state = [ state for state in previous_action_values[key]['to_states'] ] new_to_state = [state for state in gen.qstore.q[key]['to_states']] for i in range(len(old_to_state)): assert (old_to_state[i] in new_to_state)
from yapps import cli_tool cli_tool.generate('cnn.g') import cnn print cnn.parse('net', '[C(1,2,3), C(1,2,3), SM(10)]') print cnn.parse('net', '[C(1,2,3), C(4, 5, 6), FC(40), FC(40), SM(10)]') print cnn.parse('net', '[C(1,1,1), S{[C(2,2,2), C(22,22,22)], [C(3,3,3)]}, C(4,4,4), P(2), SM(10)]') print cnn.parse('net', '[C(1,2,3), NIN(100), BN, NIN(100), GAP(100)]')