예제 #1
0
import mxnet as mx
import logging
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from arg_parsing import process_args
from logger import construct_run_id, configure_root_logger
from data_loaders.cifar10 import Cifar10
from models.resnet164_basic import resnet164Basic
from learners.gluon import GluonLearner

if __name__ == "__main__":
    run_id = construct_run_id(__file__)
    configure_root_logger(run_id)
    logging.info(__file__)

    args = process_args()
    mx.random.seed(args.seed)

    batch_size = 128
    train_data, valid_data = Cifar10(
        batch_size=batch_size,
        data_shape=(3, 32, 32),
        padding=4,
        padding_value=0,
        normalization_type="channel").return_dataloaders()

    lr_schedule = {0: 0.01, 5: 0.1, 95: 0.01, 140: 0.001}

    model = resnet164Basic(num_classes=10)
예제 #2
0
def run(args):
    # Configures the root application logger.
    # After these line, it's safe to log using src.poretitioner.logger.getLogger() throughout the application.
    logger.configure_root_logger(verbosity=args.verbose, debug=args.debug)
    log = logger.getLogger()
    log.debug(f"Starting poretitioner with arguments: {vars(args)!s}")

    # Get the command line args as a dictionary.
    command_line_args = vars(args)
    if "capture_directory" not in command_line_args and getattr(
            args, ARG.GENERAL.CAPTURE_DIRECTORY, False):
        command_line_args["capture_directory"] = command_line_args[
            ARG.GENERAL.CAPTURE_DIRECTORY]

    # Read configuration file, if it exists.
    try:
        configuration_path = Path(
            command_line_args[ARG.GENERAL.CONFIG]).resolve()
    except KeyError as e:
        log.info(f"No config file found from arg: {ARG.GENERAL.CONFIG}.")
        raise e
    configuration = readconfig(configuration_path,
                               command_line_args=command_line_args,
                               log=log)
    bulk_f5_filepath = Path(
        command_line_args[ARG.GENERAL.BULK_FAST5]).resolve()

    seg_config = configuration[CONFIG.SEGMENTATION]
    filter_set: FilterSet = configuration[CONFIG.FILTER]
    config = configuration[CONFIG.GENERAL]

    save_location = Path(getattr(args,
                                 ARG.GENERAL.CAPTURE_DIRECTORY)).resolve()

    log.info(f"bulk_f5_filepath: {bulk_f5_filepath}")
    log.info(f"Save location: {save_location}")

    if args.command == COMMAND.SEGMENT:
        segmentation_config_str = pprint.pformat(seg_config.__dict__)
        general_config_str = pprint.pformat(config.__dict__)

        capture_metadata = segment.segment(
            bulk_f5_filepath,
            config,
            seg_config,
            save_location=save_location,
            sub_run_start_observations=0,
            sub_run_end_observations=None,
        )

        segment_results = pprint.pformat(capture_metadata)
        log.debug(f"All done segmenting: \n{segment_results}")
        return
    elif args.command == COMMAND.FILTER:
        # TODO: Perform filter step.
        return
    elif args.command == COMMAND.CLASSIFY:
        # TODO: Perform classification step.
        return
    elif args.command == COMMAND.QUANTIFY:
        # TODO: Perform quantification step.
        return
    else:
        # TODO: Perform all steps.
        return