def __init__(self, name, container, application, processor_type): self.application = application self.container = container self.name = name print("processor_type", processor_type) self.processor = util.cpu(processor_type) self.mem = util.memory(processor_type)
def save_weights(self, savedfile, cutoff=0): if cutoff <= 0: cutoff = len(self.blocks) - 1 fp = open(savedfile, 'wb') # Attach the header at the top of the file self.header[3] = self.seen header = self.header header = header.numpy() header.tofile(fp) # Now, let us save the weights for i in range(len(self.module_list)): module_type = self.blocks[i + 1]["type"] if (module_type) == "convolutional": model = self.module_list[i] try: batch_normalize = int(self.blocks[i + 1]["batch_normalize"]) except: batch_normalize = 0 conv = model[0] if (batch_normalize): bn = model[1] # If the parameters are on GPU, convert them back to CPU # We don't convert the parameter to GPU # Instead. we copy the parameter and then convert it to CPU # This is done as weight are need to be saved during training cpu(bn.bias.data).numpy().tofile(fp) cpu(bn.weight.data).numpy().tofile(fp) cpu(bn.running_mean).numpy().tofile(fp) cpu(bn.running_var).numpy().tofile(fp) else: cpu(conv.bias.data).numpy().tofile(fp) # Let us save the weights for the Convolutional layers cpu(conv.weight.data).numpy().tofile(fp)
def save_weights(self, savedfile, cutoff = 0): if cutoff <= 0: cutoff = len(self.blocks) - 1 fp = open(savedfile, 'wb') self.header[3] = self.seen header = self.header header = header.numpy() header.tofile(fp) for i in range(len(self.module_list)): module_type = self.blocks[i+1]["type"] if (module_type) == "convolutional": model = self.module_list[i] try: batch_normalize = int(self.blocks[i+1]["batch_normalize"]) except: batch_normalize = 0 conv = model[0] if (batch_normalize): bn = model[1] cpu(bn.bias.data).numpy().tofile(fp) cpu(bn.weight.data).numpy().tofile(fp) cpu(bn.running_mean).numpy().tofile(fp) cpu(bn.running_var).numpy().tofile(fp) else: cpu(conv.bias.data).numpy().tofile(fp) cpu(conv.weight.data).numpy().tofile(fp)