The remote monitoring system enables distributed training scenarios where training occurs on remote machines while the UI runs on a different machine. This is particularly useful for cluster computing environments and cloud-based training setups.
Background web reporting system for sending training updates to remote UI servers.
public class WebReporter {
// Singleton access
public static WebReporter getInstance();
// Asynchronous reporting (queues for background processing)
public void queueReport(WebTarget target, Entity entity);
// Synchronous reporting (immediate POST request)
public void postReport(WebTarget target, Entity entity);
}Important Note: The current WebReporter implementation throws RuntimeException("Not implemented") in the constructor, indicating this class is not fully functional in version 0.9.1. Use remote iteration listeners or remote storage routers instead for reliable remote monitoring.
Remote version of the histogram iteration listener for weight and gradient visualization.
public class RemoteHistogramIterationListener implements IterationListener {
// Constructors
public RemoteHistogramIterationListener(String serverAddress);
public RemoteHistogramIterationListener(String serverAddress, int frequency);
public RemoteHistogramIterationListener(String serverAddress, int frequency,
HttpClientBuilder httpClientBuilder);
// Configuration
public void setStorageRouter(StatsStorageRouter router);
public void setFrequency(int frequency);
// Lifecycle
public void iterationDone(Model model, int iteration, int epoch);
}Remote version of the flow iteration listener for network architecture visualization.
public class RemoteFlowIterationListener implements IterationListener {
// Constructors
public RemoteFlowIterationListener(String serverAddress);
public RemoteFlowIterationListener(String serverAddress, int frequency);
public RemoteFlowIterationListener(String serverAddress, int frequency,
HttpClientBuilder httpClientBuilder);
// Configuration
public void setCollectActivations(boolean collect);
public void setCollectGradients(boolean collect);
public void setFrequency(int frequency);
// Lifecycle
public void iterationDone(Model model, int iteration, int epoch);
}Remote version of the convolutional iteration listener for CNN-specific visualizations.
public class RemoteConvolutionalIterationListener implements IterationListener {
// Constructors
public RemoteConvolutionalIterationListener(String serverAddress);
public RemoteConvolutionalIterationListener(String serverAddress, int frequency);
public RemoteConvolutionalIterationListener(String serverAddress, int frequency,
HttpClientBuilder httpClientBuilder);
// Configuration
public void setCollectActivations(boolean collect);
public void setCollectionLayers(List<String> layerNames);
public void setFrequency(int frequency);
// Lifecycle
public void iterationDone(Model model, int iteration, int epoch);
}Router for sending statistics to remote UI servers.
public class RemoteUIStatsStorageRouter implements StatsStorageRouter {
// Constructors
public RemoteUIStatsStorageRouter(String serverAddress);
public RemoteUIStatsStorageRouter(String serverAddress, HttpClientBuilder httpClientBuilder);
// StatsStorageRouter implementation
public void putStaticInfo(Persistable staticInfo);
public void putUpdate(Persistable update);
public void putStorageMetaData(StorageMetaData storageMetaData);
// Configuration
public void setServerAddress(String address);
public String getServerAddress();
}Configuration classes for remote connections.
public class UiConnectionInfo {
// Connection details
private String address;
private int port;
private String protocol;
private String path;
// Constructors
public UiConnectionInfo(String address);
public UiConnectionInfo(String address, int port);
public UiConnectionInfo(String protocol, String address, int port, String path);
// Accessors
public String getAddress();
public int getPort();
public String getProtocol();
public String getPath();
public String getFullAddress();
}import org.deeplearning4j.ui.weights.RemoteHistogramIterationListener;
import org.deeplearning4j.ui.flow.RemoteFlowIterationListener;
// Configure remote UI server address
String uiServerAddress = "http://ui-server:9000";
// Create remote listeners
RemoteHistogramIterationListener histogramListener =
new RemoteHistogramIterationListener(uiServerAddress, 10);
RemoteFlowIterationListener flowListener =
new RemoteFlowIterationListener(uiServerAddress, 50);
// Attach to model
MultiLayerNetwork model = new MultiLayerNetwork(config);
model.init();
model.setListeners(histogramListener, flowListener);
// Train model - data will be sent to remote UI server
model.fit(trainingData);import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.client.config.RequestConfig;
// Configure HTTP client with custom timeouts
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(5000)
.setSocketTimeout(10000)
.setConnectionRequestTimeout(5000)
.build();
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create()
.setDefaultRequestConfig(requestConfig)
.setMaxConnTotal(10)
.setMaxConnPerRoute(5);
// Create remote listener with custom HTTP client
RemoteHistogramIterationListener listener = new RemoteHistogramIterationListener(
uiServerAddress, 10, httpClientBuilder);
model.setListeners(listener);import org.deeplearning4j.api.storage.impl.RemoteUIStatsStorageRouter;
import org.deeplearning4j.ui.stats.StatsListener;
// Create remote storage router
RemoteUIStatsStorageRouter remoteRouter =
new RemoteUIStatsStorageRouter("http://ui-server:9000");
// Use with standard StatsListener for modern approach
StatsListener statsListener = new StatsListener(remoteRouter);
model.setListeners(statsListener);// Send data to multiple UI servers
String[] uiServers = {
"http://ui-server-1:9000",
"http://ui-server-2:9000",
"http://backup-ui-server:9000"
};
List<RemoteHistogramIterationListener> remoteListeners = new ArrayList<>();
for (String serverAddress : uiServers) {
RemoteHistogramIterationListener listener =
new RemoteHistogramIterationListener(serverAddress, 10);
remoteListeners.add(listener);
}
// Add all remote listeners to model
model.setListeners(remoteListeners.toArray(new IterationListener[0]));import javax.net.ssl.SSLContext;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
// Configure SSL for secure connections
SSLContext sslContext = SSLContext.getDefault();
SSLConnectionSocketFactory sslConnectionFactory =
new SSLConnectionSocketFactory(sslContext);
HttpClientBuilder secureClientBuilder = HttpClientBuilder.create()
.setSSLSocketFactory(sslConnectionFactory);
// Create secure remote listener
RemoteHistogramIterationListener secureListener = new RemoteHistogramIterationListener(
"https://secure-ui-server:9443", 10, secureClientBuilder);
model.setListeners(secureListener);import org.deeplearning4j.ui.WebReporter;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.client.Entity;
// Custom reporter with error handling
WebReporter reporter = WebReporter.getInstance();
// Queue reports with automatic retry
try {
reporter.queueReport(webTarget, entity);
} catch (Exception e) {
// Handle network errors
System.err.println("Failed to send report: " + e.getMessage());
// Implement retry logic or fallback storage
// ... retry or store locally for later transmission
}// Enable remote reporting only in certain environments
String environment = System.getProperty("environment", "local");
boolean enableRemoteReporting = "production".equals(environment) || "staging".equals(environment);
if (enableRemoteReporting) {
String uiServerAddress = System.getProperty("ui.server.address", "http://localhost:9000");
RemoteHistogramIterationListener remoteListener =
new RemoteHistogramIterationListener(uiServerAddress, 10);
model.setListeners(remoteListener);
} else {
// Use local UI server for development
UIServer localServer = UIServer.getInstance();
InMemoryStatsStorage localStorage = new InMemoryStatsStorage();
localServer.attach(localStorage);
StatsListener localListener = new StatsListener(localStorage);
model.setListeners(localListener);
}import org.deeplearning4j.ui.UiConnectionInfo;
// Create connection info
UiConnectionInfo connectionInfo = new UiConnectionInfo("ui-server", 9000);
// Or with full configuration
UiConnectionInfo fullConnectionInfo = new UiConnectionInfo(
"https", "ui-server", 9443, "/ui/monitoring");
// Use with remote listeners
RemoteHistogramIterationListener listener =
new RemoteHistogramIterationListener(fullConnectionInfo.getFullAddress());import org.deeplearning4j.ui.WebReporter;
// Configure batch reporting for efficiency
WebReporter reporter = WebReporter.getInstance();
// Queue multiple reports - they will be sent in background
for (int i = 0; i < trainingBatches.size(); i++) {
// Train batch
model.fit(trainingBatches.get(i));
// Reports are automatically queued by remote listeners
// and sent asynchronously to avoid blocking training
}Ensure the following ports are accessible:
For high-availability setups: