Search in sources :

Example 1 with ParameterException

use of com.beust.jcommander.ParameterException in project deeplearning4j by deeplearning4j.

the class ParallelWrapperMain method runMain.

public void runMain(String... args) throws Exception {
    JCommander jcmdr = new JCommander(this);
    try {
        jcmdr.parse(args);
    } catch (ParameterException e) {
        System.err.println(e.getMessage());
        //User provides invalid input -> print the usage info
        jcmdr.usage();
        try {
            Thread.sleep(500);
        } catch (Exception e2) {
        }
        System.exit(1);
    }
    Model model = ModelGuesser.loadModelGuess(modelPath);
    // ParallelWrapper will take care of load balancing between GPUs.
    ParallelWrapper wrapper = new ParallelWrapper.Builder(model).prefetchBuffer(prefetchSize).workers(workers).averagingFrequency(averagingFrequency).averageUpdaters(averageUpdaters).reportScoreAfterAveraging(reportScore).useLegacyAveraging(legacyAveraging).build();
    if (dataSetIteratorFactoryClazz != null) {
        DataSetIteratorProviderFactory dataSetIteratorProviderFactory = (DataSetIteratorProviderFactory) Class.forName(dataSetIteratorFactoryClazz).newInstance();
        DataSetIterator dataSetIterator = dataSetIteratorProviderFactory.create();
        if (uiUrl != null) {
            // it's important that the UI can report results from parallel training
            // there's potential for StatsListener to fail if certain properties aren't set in the model
            StatsStorageRouter remoteUIRouter = new RemoteUIStatsStorageRouter("http://" + uiUrl);
            wrapper.setListeners(remoteUIRouter, new StatsListener(null));
        }
        wrapper.fit(dataSetIterator);
        ModelSerializer.writeModel(model, new File(modelOutputPath), true);
    } else if (multiDataSetIteratorFactoryClazz != null) {
        MultiDataSetProviderFactory multiDataSetProviderFactory = (MultiDataSetProviderFactory) Class.forName(multiDataSetIteratorFactoryClazz).newInstance();
        MultiDataSetIterator iterator = multiDataSetProviderFactory.create();
        if (uiUrl != null) {
            // it's important that the UI can report results from parallel training
            // there's potential for StatsListener to fail if certain properties aren't set in the model
            StatsStorageRouter remoteUIRouter = new RemoteUIStatsStorageRouter("http://" + uiUrl);
            wrapper.setListeners(remoteUIRouter, new StatsListener(null));
        }
        wrapper.fit(iterator);
        ModelSerializer.writeModel(model, new File(modelOutputPath), true);
    } else {
        throw new IllegalStateException("Please provide a datasetiteraator or multi datasetiterator class");
    }
}
Also used : ParallelWrapper(org.deeplearning4j.parallelism.ParallelWrapper) StatsStorageRouter(org.deeplearning4j.api.storage.StatsStorageRouter) RemoteUIStatsStorageRouter(org.deeplearning4j.api.storage.impl.RemoteUIStatsStorageRouter) StatsListener(org.deeplearning4j.ui.stats.StatsListener) ParameterException(com.beust.jcommander.ParameterException) MultiDataSetIterator(org.nd4j.linalg.dataset.api.iterator.MultiDataSetIterator) JCommander(com.beust.jcommander.JCommander) Model(org.deeplearning4j.nn.api.Model) RemoteUIStatsStorageRouter(org.deeplearning4j.api.storage.impl.RemoteUIStatsStorageRouter) ParameterException(com.beust.jcommander.ParameterException) File(java.io.File) DataSetIterator(org.nd4j.linalg.dataset.api.iterator.DataSetIterator) MultiDataSetIterator(org.nd4j.linalg.dataset.api.iterator.MultiDataSetIterator)

Example 2 with ParameterException

use of com.beust.jcommander.ParameterException in project deeplearning4j by deeplearning4j.

the class PlayUIServer method runMain.

public void runMain(String[] args) {
    JCommander jcmdr = new JCommander(this);
    try {
        jcmdr.parse(args);
    } catch (ParameterException e) {
        //User provides invalid input -> print the usage info
        jcmdr.usage();
        try {
            Thread.sleep(500);
        } catch (Exception e2) {
        }
        System.exit(1);
    }
    RoutingDsl routingDsl = new RoutingDsl();
    //Set up index page and assets routing
    //The definitions and FunctionUtil may look a bit weird here... this is used to translate implementation independent
    // definitions (i.e., Java Supplier, Function etc interfaces) to the Play-specific versions
    //This way, routing is not directly dependent ot Play API. Furthermore, Play 2.5 switches to using these Java interfaces
    // anyway; thus switching 2.5 should be as simple as removing the FunctionUtil calls...
    routingDsl.GET("/setlang/:to").routeTo(FunctionUtil.function(new I18NRoute()));
    routingDsl.GET("/lang/getCurrent").routeTo(() -> ok(I18NProvider.getInstance().getDefaultLanguage()));
    routingDsl.GET("/assets/*file").routeTo(FunctionUtil.function(new Assets(ASSETS_ROOT_DIRECTORY)));
    //For: navigation page "/"
    uiModules.add(new DefaultModule());
    uiModules.add(new HistogramModule());
    uiModules.add(new TrainModule());
    uiModules.add(new ConvolutionalListenerModule());
    uiModules.add(new FlowListenerModule());
    uiModules.add(new TsneModule());
    remoteReceiverModule = new RemoteReceiverModule();
    uiModules.add(remoteReceiverModule);
    //Check if custom UI modules are enabled...
    String customModulePropertyStr = System.getProperty(UI_CUSTOM_MODULE_PROPERTY);
    boolean useCustomModules = false;
    if (customModulePropertyStr != null) {
        useCustomModules = Boolean.parseBoolean(customModulePropertyStr);
    }
    if (useCustomModules) {
        List<Class<?>> excludeClasses = new ArrayList<>();
        for (UIModule u : uiModules) {
            excludeClasses.add(u.getClass());
        }
        List<UIModule> list = getCustomUIModules(excludeClasses);
        uiModules.addAll(list);
    }
    for (UIModule m : uiModules) {
        List<Route> routes = m.getRoutes();
        for (Route r : routes) {
            RoutingDsl.PathPatternMatcher ppm = routingDsl.match(r.getHttpMethod().name(), r.getRoute());
            switch(r.getFunctionType()) {
                case Supplier:
                    ppm.routeTo(FunctionUtil.function0(r.getSupplier()));
                    break;
                case Function:
                    ppm.routeTo(FunctionUtil.function(r.getFunction()));
                    break;
                case BiFunction:
                case Function3:
                default:
                    throw new RuntimeException("Not yet implemented");
            }
        }
        //Determine which type IDs this module wants to receive:
        List<String> typeIDs = m.getCallbackTypeIDs();
        for (String typeID : typeIDs) {
            List<UIModule> list = typeIDModuleMap.get(typeID);
            if (list == null) {
                list = Collections.synchronizedList(new ArrayList<>());
                typeIDModuleMap.put(typeID, list);
            }
            list.add(m);
        }
    }
    String portProperty = System.getProperty(UI_SERVER_PORT_PROPERTY);
    Router router = routingDsl.build();
    server = Server.forRouter(router, Mode.DEV, port);
    this.port = port;
    String addr = server.mainAddress().toString();
    if (addr.startsWith("/0:0:0:0:0:0:0:0")) {
        int last = addr.lastIndexOf(':');
        if (last > 0) {
            addr = "http://localhost:" + addr.substring(last + 1);
        }
    }
    log.info("UI Server started at {}", addr);
    uiEventRoutingThread = new Thread(new StatsEventRouterRunnable());
    uiEventRoutingThread.setDaemon(true);
    uiEventRoutingThread.start();
    if (enableRemote)
        enableRemoteListener();
}
Also used : I18NRoute(org.deeplearning4j.ui.play.staticroutes.I18NRoute) DefaultModule(org.deeplearning4j.ui.module.defaultModule.DefaultModule) HistogramModule(org.deeplearning4j.ui.module.histogram.HistogramModule) TrainModule(org.deeplearning4j.ui.module.train.TrainModule) FlowListenerModule(org.deeplearning4j.ui.module.flow.FlowListenerModule) JCommander(com.beust.jcommander.JCommander) Assets(org.deeplearning4j.ui.play.staticroutes.Assets) ParameterException(com.beust.jcommander.ParameterException) RemoteReceiverModule(org.deeplearning4j.ui.module.remote.RemoteReceiverModule) Route(org.deeplearning4j.ui.api.Route) I18NRoute(org.deeplearning4j.ui.play.staticroutes.I18NRoute) StatsStorageRouter(org.deeplearning4j.api.storage.StatsStorageRouter) Router(play.api.routing.Router) ParameterException(com.beust.jcommander.ParameterException) RoutingDsl(play.routing.RoutingDsl) UIModule(org.deeplearning4j.ui.api.UIModule) TsneModule(org.deeplearning4j.ui.module.tsne.TsneModule) ConvolutionalListenerModule(org.deeplearning4j.ui.module.convolutional.ConvolutionalListenerModule)

Example 3 with ParameterException

use of com.beust.jcommander.ParameterException in project jsonschema2pojo by joelittlejohn.

the class Arguments method parse.

/**
     * Parses command line arguments and populates this command line instance.
     * <p>
     * If the command line arguments include the "help" argument, or if the
     * arguments have incorrect values or order, then usage information is
     * printed to {@link System#out} and the program terminates.
     *
     * @param args
     *            the command line arguments
     * @return an instance of the parsed arguments object
     */
public Arguments parse(String[] args) {
    JCommander jCommander = new JCommander(this);
    jCommander.setProgramName("jsonschema2pojo");
    try {
        jCommander.parse(args);
        if (this.showHelp) {
            jCommander.usage();
            exit(EXIT_OKAY);
        }
    } catch (ParameterException e) {
        System.err.println(e.getMessage());
        jCommander.usage();
        exit(EXIT_ERROR);
    }
    return this;
}
Also used : JCommander(com.beust.jcommander.JCommander) ParameterException(com.beust.jcommander.ParameterException)

Example 4 with ParameterException

use of com.beust.jcommander.ParameterException in project keywhiz by square.

the class CliMain method main.

public static void main(String[] args) throws Exception {
    CliConfiguration config = new CliConfiguration();
    JCommander commander = new JCommander();
    Map<String, Object> commands = ImmutableMap.<String, Object>builder().put("login", new LoginActionConfig()).put("list", new ListActionConfig()).put("describe", new DescribeActionConfig()).put("add", new AddActionConfig()).put("update", new UpdateActionConfig()).put("delete", new DeleteActionConfig()).put("assign", new AssignActionConfig()).put("unassign", new UnassignActionConfig()).put("versions", new ListVersionsActionConfig()).put("rollback", new RollbackActionConfig()).build();
    commander.setProgramName("KeyWhiz Configuration Utility");
    commander.addObject(config);
    for (Map.Entry<String, Object> entry : commands.entrySet()) {
        commander.addCommand(entry.getKey(), entry.getValue());
    }
    try {
        commander.parse(args);
    } catch (ParameterException e) {
        System.err.println("Invalid command: " + e.getMessage());
        commander.usage();
        System.exit(1);
    }
    String command = commander.getParsedCommand();
    JCommander specificCommander = commander.getCommands().get(command);
    Injector injector = Guice.createInjector(new CliModule(config, commander, specificCommander, command, commands));
    CommandExecutor executor = injector.getInstance(CommandExecutor.class);
    executor.executeCommand();
}
Also used : JCommander(com.beust.jcommander.JCommander) Injector(com.google.inject.Injector) ParameterException(com.beust.jcommander.ParameterException) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 5 with ParameterException

use of com.beust.jcommander.ParameterException in project disunity by ata4.

the class DisUnityCli method main.

/**
     * @param args the command line arguments
     */
public static void main(String[] args) {
    LogUtils.configure();
    try (PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out), true)) {
        JCommander jc = new JCommander();
        DisUnityRoot root = new DisUnityRoot();
        root.init(jc, out);
        jc.setProgramName(DisUnity.getProgramName());
        jc.addObject(root);
        jc.parse(args);
        root.run();
    } catch (ParameterException ex) {
        L.log(Level.WARNING, "Parameter error: {0}", ex.getMessage());
    } catch (Throwable t) {
        L.log(Level.SEVERE, "Fatal error", t);
    }
}
Also used : JCommander(com.beust.jcommander.JCommander) OutputStreamWriter(java.io.OutputStreamWriter) ParameterException(com.beust.jcommander.ParameterException) DisUnityRoot(info.ata4.disunity.cli.command.DisUnityRoot) PrintWriter(java.io.PrintWriter)

Aggregations

ParameterException (com.beust.jcommander.ParameterException)19 JCommander (com.beust.jcommander.JCommander)15 RateLimiter (com.google.common.util.concurrent.RateLimiter)4 PulsarClient (com.yahoo.pulsar.client.api.PulsarClient)4 FileInputStream (java.io.FileInputStream)4 Message (com.yahoo.pulsar.client.api.Message)3 File (java.io.File)3 IOException (java.io.IOException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)2 ClientConfiguration (com.yahoo.pulsar.client.api.ClientConfiguration)2 Consumer (com.yahoo.pulsar.client.api.Consumer)2 ConsumerConfiguration (com.yahoo.pulsar.client.api.ConsumerConfiguration)2 Producer (com.yahoo.pulsar.client.api.Producer)2 PulsarClientException (com.yahoo.pulsar.client.api.PulsarClientException)2 PulsarClientImpl (com.yahoo.pulsar.client.impl.PulsarClientImpl)2 DestinationName (com.yahoo.pulsar.common.naming.DestinationName)2 EventLoopGroup (io.netty.channel.EventLoopGroup)2 EpollEventLoopGroup (io.netty.channel.epoll.EpollEventLoopGroup)2 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)2