Search in sources :

Example 1 with UIModule

use of org.deeplearning4j.ui.api.UIModule in project deeplearning4j by deeplearning4j.

the class PlayUIServer method detach.

@Override
public synchronized void detach(StatsStorage statsStorage) {
    if (statsStorage == null)
        throw new IllegalArgumentException("StatsStorage cannot be null");
    if (!statsStorageInstances.contains(statsStorage))
        //No op
        return;
    boolean found = false;
    for (Pair<StatsStorage, StatsStorageListener> p : listeners) {
        if (p.getFirst() == statsStorage) {
            //Same object, not equality
            statsStorage.deregisterStatsStorageListener(p.getSecond());
            listeners.remove(p);
            found = true;
        }
    }
    for (UIModule uiModule : uiModules) {
        uiModule.onDetach(statsStorage);
    }
    if (found) {
        log.info("StatsStorage instance detached from UI: {}", statsStorage);
    }
}
Also used : InMemoryStatsStorage(org.deeplearning4j.ui.storage.InMemoryStatsStorage) StatsStorage(org.deeplearning4j.api.storage.StatsStorage) UIModule(org.deeplearning4j.ui.api.UIModule) QueuePairStatsStorageListener(org.deeplearning4j.ui.storage.impl.QueuePairStatsStorageListener) StatsStorageListener(org.deeplearning4j.api.storage.StatsStorageListener) QueueStatsStorageListener(org.deeplearning4j.ui.storage.impl.QueueStatsStorageListener)

Example 2 with UIModule

use of org.deeplearning4j.ui.api.UIModule 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 UIModule

use of org.deeplearning4j.ui.api.UIModule in project deeplearning4j by deeplearning4j.

the class PlayUIServer method attach.

@Override
public synchronized void attach(StatsStorage statsStorage) {
    if (statsStorage == null)
        throw new IllegalArgumentException("StatsStorage cannot be null");
    if (statsStorageInstances.contains(statsStorage))
        return;
    StatsStorageListener listener = new QueueStatsStorageListener(eventQueue);
    listeners.add(new Pair<>(statsStorage, listener));
    statsStorage.registerStatsStorageListener(listener);
    statsStorageInstances.add(statsStorage);
    for (UIModule uiModule : uiModules) {
        uiModule.onAttach(statsStorage);
    }
    log.info("StatsStorage instance attached to UI: {}", statsStorage);
}
Also used : QueueStatsStorageListener(org.deeplearning4j.ui.storage.impl.QueueStatsStorageListener) UIModule(org.deeplearning4j.ui.api.UIModule) QueuePairStatsStorageListener(org.deeplearning4j.ui.storage.impl.QueuePairStatsStorageListener) StatsStorageListener(org.deeplearning4j.api.storage.StatsStorageListener) QueueStatsStorageListener(org.deeplearning4j.ui.storage.impl.QueueStatsStorageListener)

Example 4 with UIModule

use of org.deeplearning4j.ui.api.UIModule in project deeplearning4j by deeplearning4j.

the class PlayUIServer method getCustomUIModules.

private List<UIModule> getCustomUIModules(List<Class<?>> excludeClasses) {
    //Scan classpath for UI module instances, but ignore the 'excludeClasses' classes
    List<String> classNames = Collections.singletonList(UIModule.class.getName());
    Reflections reflections = new Reflections();
    org.reflections.Store store = reflections.getStore();
    Iterable<String> subtypesByName = store.getAll(org.reflections.scanners.SubTypesScanner.class.getSimpleName(), classNames);
    Set<? extends Class<?>> subtypeClasses = Sets.newHashSet(ReflectionUtils.forNames(subtypesByName));
    List<Class<?>> toCreate = new ArrayList<>();
    for (Class<?> c : subtypeClasses) {
        if (excludeClasses.contains(c))
            continue;
        ;
        toCreate.add(c);
    }
    List<UIModule> ret = new ArrayList<>(toCreate.size());
    for (Class<?> c : toCreate) {
        UIModule m;
        try {
            m = (UIModule) c.newInstance();
        } catch (Exception e) {
            log.warn("Could not create instance of custom UIModule of type {}; skipping", c, e);
            continue;
        }
        log.debug("Created instance of custom UI module: {}", c);
        ret.add(m);
    }
    return ret;
}
Also used : ParameterException(com.beust.jcommander.ParameterException) UIModule(org.deeplearning4j.ui.api.UIModule) Reflections(org.reflections.Reflections)

Aggregations

UIModule (org.deeplearning4j.ui.api.UIModule)4 ParameterException (com.beust.jcommander.ParameterException)2 StatsStorageListener (org.deeplearning4j.api.storage.StatsStorageListener)2 QueuePairStatsStorageListener (org.deeplearning4j.ui.storage.impl.QueuePairStatsStorageListener)2 QueueStatsStorageListener (org.deeplearning4j.ui.storage.impl.QueueStatsStorageListener)2 JCommander (com.beust.jcommander.JCommander)1 StatsStorage (org.deeplearning4j.api.storage.StatsStorage)1 StatsStorageRouter (org.deeplearning4j.api.storage.StatsStorageRouter)1 Route (org.deeplearning4j.ui.api.Route)1 ConvolutionalListenerModule (org.deeplearning4j.ui.module.convolutional.ConvolutionalListenerModule)1 DefaultModule (org.deeplearning4j.ui.module.defaultModule.DefaultModule)1 FlowListenerModule (org.deeplearning4j.ui.module.flow.FlowListenerModule)1 HistogramModule (org.deeplearning4j.ui.module.histogram.HistogramModule)1 RemoteReceiverModule (org.deeplearning4j.ui.module.remote.RemoteReceiverModule)1 TrainModule (org.deeplearning4j.ui.module.train.TrainModule)1 TsneModule (org.deeplearning4j.ui.module.tsne.TsneModule)1 Assets (org.deeplearning4j.ui.play.staticroutes.Assets)1 I18NRoute (org.deeplearning4j.ui.play.staticroutes.I18NRoute)1 InMemoryStatsStorage (org.deeplearning4j.ui.storage.InMemoryStatsStorage)1 Reflections (org.reflections.Reflections)1