예제 #1
0
 def save_model(self, path):
     """
     It saves the model on disk as well as the weights assigned to the
     neurons in the network
     :param path: path where the model and weight files should be stored
     """
     if not os.path.exists(path):
         self.logger.info('Model - Path [{}] does not exist. Creating...'
                          ''.format(path))
         create_dir(path)
     self.model.save(os.path.join(path, self.name + '_model.h5'))
     self.model.save_weights(os.path.join(path, self.name + '_weights.h5'))
예제 #2
0
def main(args):

    utils.create_dir(args.outputdir)

    if args.parser_mode == 'dfw_services' or args.parser_mode == 'dfw_appliedto':
        utils.validate_file(args.rules, args.debug)
    if args.parser_mode == 'dfw_appliedto':
        utils.validate_file(args.addrsets, args.debug)

    args.prefix = '%s-' % (args.prefix)
    parsedRules = RulesParser(args.rules, args.debug)

    if args.parser_mode == 'dfw_services':
        process_services(parsedRules, args)

    if args.parser_mode == 'dfw_appliedto':
        process_applied_to(parsedRules, args)

    # Display any parsing errors at the end
    parsedRules.parse_errors(args.outputdir, args.prefix)
예제 #3
0
 def save_figure(self, fig, name, path=None, append_date=True):
     """
     Function that saves the figure passed as param in the path given.
     :param fig: Figure object that will be saved as image
     :param name: Name of the image
     :param path: Target path
     :param append_date: Boolean that specifies if date should be appended
     to image name
     """
     if not path:
         path = self.fig_path
     if not os.path.exists(path):
         self.logger.info('Model - Path [{}] does not exist. Creating...'
                          ''.format(path))
         create_dir(path)
     if append_date:
         name = '{}_{}.png'.format(name,
                                   datetime.now().strftime('%Y%m%d%H%M%S'))
     fig.savefig(os.path.join(path, name))
     self.logger.info('Model - Figure was saved in [{}]'.format(
         os.path.join(path, name)))
예제 #4
0
 def prepare_data_in_folders(self, x, y, path):
     """
     It copies images into their corresponding class folders.
     :param x: list of images paths
     :param y: list of classes/labels
     :param path: base path where class folders will be created
     """
     full_path = os.path.abspath(path)
     if os.path.exists(full_path):
         # just in case it exists and contains previous executions data
         remove_dir(full_path)
     else:
         create_dir(full_path)
     i = 0
     for f in x:
         fname = f.split('/')[-1]
         cls = get_value(y[i], self.classes)
         dst = os.path.join(full_path, cls)
         if not os.path.exists(dst):
             create_dir(dst)
         dst = os.path.join(dst, fname)
         copy_file(f, dst)
         i += 1