Rank is [4]; columns() call is not valid - UNET implementation has a weird error

I have recreated the UNET implementation almost exactly, except halved the number of inputs. Somehow it errors out after 16 iterations saying that columns() is being called incorrectly from deep within dl4j. Here is my code and at the bottom I will post the stack trace to the error. I am using a 2049x2049 image for training and another 2049x2049 image for labeling. I divide the image up into 64 smaller images and put them in a dataset before feeding them to the network. Thank you in advance for any help. Let me know if I can provide any other information.

package com.asinm.pix2net.neuralnetwork;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.bytedeco.javacpp.opencv_core.Mat;
import org.bytedeco.javacpp.opencv_core.Rect;
import org.datavec.image.loader.NativeImageLoader;
import org.deeplearning4j.datasets.iterator.impl.ListDataSetIterator;
import org.deeplearning4j.nn.api.Model;
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
import org.deeplearning4j.nn.conf.CacheMode;
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
import org.deeplearning4j.nn.conf.ConvolutionMode;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.WorkspaceMode;
import org.deeplearning4j.nn.conf.graph.MergeVertex;
import org.deeplearning4j.nn.conf.inputs.InputType;
import org.deeplearning4j.nn.conf.layers.CnnLossLayer;
import org.deeplearning4j.nn.conf.layers.ConvolutionLayer;
import org.deeplearning4j.nn.conf.layers.DropoutLayer;
import org.deeplearning4j.nn.conf.layers.SubsamplingLayer;
import org.deeplearning4j.nn.conf.layers.Upsampling2D;
import org.deeplearning4j.nn.graph.ComputationGraph;
import org.deeplearning4j.nn.weights.WeightInit;
import org.deeplearning4j.optimize.api.InvocationType;
import org.deeplearning4j.optimize.listeners.EvaluativeListener;
import org.deeplearning4j.optimize.listeners.ScoreIterationListener;
import org.deeplearning4j.ui.api.UIServer;
import org.deeplearning4j.ui.stats.StatsListener;
import org.deeplearning4j.ui.storage.InMemoryStatsStorage;
import org.deeplearning4j.util.ModelSerializer;
import org.deeplearning4j.zoo.ModelMetaData;
import org.deeplearning4j.zoo.ZooType;
import org.nd4j.linalg.activations.Activation;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.dataset.DataSet;
import org.nd4j.linalg.dataset.api.iterator.DataSetIterator;
import org.nd4j.linalg.learning.config.AdaDelta;
import org.nd4j.linalg.learning.config.IUpdater;
import org.nd4j.linalg.lossfunctions.LossFunctions;

/**

  • @author Jeffrey Gordon
  •     A modified version of the UNet neural network from the DeepLearning4J
    
  •     Zoo Models. For the purpose of memory management all of the nodes
    
  •     have been reduced to half their typical values. The layer buffer has
    
  •     also been slightly modified to more appropriately match the older
    
  •     Caffe version of the Neural Network.
    
  •     Via the DeepLearning4J API this should run on CUDA version 8.0+ and
    
  •     9.0+. It should also automatically detect the presence of multiple
    
  •     GPU's and utilize them. For any future developers looking at this
    
  •     model, DO NOT change the layer structure, this will significantly
    
  •     change the neural network's behavior. The kernel size is also
    
  •     incredibly sensitive and should never be changed. Only modify the
    
  •     neuron count at any given level and keep the neuron count as powers
    
  •     of 2, i.e. {256, 512, 1024, etc...}. Though realize increasing the
    
  •     neuron count will significantly increase memory usage.
    
  •     For example, if layer 1 is a nout(128), and layer 2 is a nout(256),
    
  •     then that means layer 1 is feeding 128 images into layer 2, and layer
    
  •     2 has 256 3x3 kernels, and layer 2 will apply each 3x3 kernel to all
    
  •     of the input images, for a total of 128 * 256 total convolutions. So,
    
  •     larger numbers means using a lot more memory on the GPU, and it takes
    
  •     a lot longer to train the network.
    

*/

@SuppressWarnings({ “rawtypes”, “deprecation” })
public class MSINeuralNetwork implements INeuralNetwork {

private long seed = 1234;
private int[] inputShape;
private int numClasses = 0;
private WeightInit weightInit = WeightInit.RELU;
private IUpdater updater = new AdaDelta();
private CacheMode cacheMode = CacheMode.NONE;
private WorkspaceMode workspaceMode = WorkspaceMode.ENABLED;
private ConvolutionLayer.AlgoMode cudnnAlgoMode = ConvolutionLayer.AlgoMode.PREFER_FASTEST;
private int frequency = 5000;
private int inputSize = 256;
private ComputationGraph graph;
private DataSetIterator dataSetIterator;
private int margin;

public static void main(String[] args) throws IOException {
	MSINeuralNetwork network = new MSINeuralNetwork(3, 256, 256);
	network.init();
	
	List<MatContainer> containers = new ArrayList<>();
	containers.add(new MatContainer("C:\\Users\\djkresta\\Documents\\neuralnetwork\\src\\test\\1\\2.png", "C:\\Users\\djkresta\\Documents\\neuralnetwork\\src\\test\\1\\2_label.png"));
	
	UIServer uiServer = UIServer.getInstance();
    InMemoryStatsStorage statsStorage = new InMemoryStatsStorage();
    uiServer.attach(statsStorage);
    
	network.trainNetwork(containers, statsStorage);
}

public MSINeuralNetwork(int channels, int xDimension, int yDimension) {
	this.inputShape = new int[] { channels, xDimension, yDimension };
}

public Class<? extends Model> modelType() {
	return ComputationGraph.class;
}

@SuppressWarnings("unchecked")
public void init() {
	ComputationGraphConfiguration.GraphBuilder graph = graphBuilder();

	graph.addInputs("input").setInputTypes(InputType.convolutional(inputShape[2], inputShape[1], inputShape[0]));

	ComputationGraphConfiguration conf = graph.build();
	ComputationGraph model = new ComputationGraph(conf);
	model.init();
	
	this.graph = model;
}

/**
 * Builds the neural network. Call this when you're ready to initialize the
 * network.
 */

public ComputationGraphConfiguration.GraphBuilder graphBuilder() {

	ComputationGraphConfiguration.GraphBuilder graph = new NeuralNetConfiguration.Builder().seed(seed)
			.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
			.updater(updater)
			.weightInit(weightInit)
			.l2(5e-5)
			.miniBatch(true)
			.cacheMode(cacheMode)
			.trainingWorkspaceMode(workspaceMode)
			.inferenceWorkspaceMode(workspaceMode)
			.graphBuilder();

	graph.addLayer("conv1-1",
			new ConvolutionLayer.Builder(3, 3).stride(1, 1).nOut(32).convolutionMode(ConvolutionMode.Same)
					.cudnnAlgoMode(cudnnAlgoMode).activation(Activation.RELU).build(),
			"input")
			.addLayer("conv1-2",
					new ConvolutionLayer.Builder(3, 3).stride(1, 1).nOut(32).convolutionMode(ConvolutionMode.Same)
							.cudnnAlgoMode(cudnnAlgoMode).activation(Activation.RELU).build(),
					"conv1-1")
			.addLayer("pool1",
					new SubsamplingLayer.Builder(SubsamplingLayer.PoolingType.MAX).kernelSize(2, 2).build(),
					"conv1-2")

			.addLayer("conv2-1",
					new ConvolutionLayer.Builder(3, 3).stride(1, 1).nOut(64).convolutionMode(ConvolutionMode.Same)
							.cudnnAlgoMode(cudnnAlgoMode).activation(Activation.RELU).build(),
					"pool1")
			.addLayer("conv2-2",
					new ConvolutionLayer.Builder(3, 3).stride(1, 1).nOut(64).convolutionMode(ConvolutionMode.Same)
							.cudnnAlgoMode(cudnnAlgoMode).activation(Activation.RELU).build(),
					"conv2-1")
			.addLayer("pool2",
					new SubsamplingLayer.Builder(SubsamplingLayer.PoolingType.MAX).kernelSize(2, 2).build(),
					"conv2-2")

			.addLayer("conv3-1",
					new ConvolutionLayer.Builder(3, 3).stride(1, 1).nOut(128).convolutionMode(ConvolutionMode.Same)
							.cudnnAlgoMode(cudnnAlgoMode).activation(Activation.RELU).build(),
					"pool2")
			.addLayer("conv3-2",
					new ConvolutionLayer.Builder(3, 3).stride(1, 1).nOut(128).convolutionMode(ConvolutionMode.Same)
							.cudnnAlgoMode(cudnnAlgoMode).activation(Activation.RELU).build(),
					"conv3-1")
			.addLayer("pool3",
					new SubsamplingLayer.Builder(SubsamplingLayer.PoolingType.MAX).kernelSize(2, 2).build(),
					"conv3-2")

			.addLayer("conv4-1",
					new ConvolutionLayer.Builder(3, 3).stride(1, 1).nOut(256).convolutionMode(ConvolutionMode.Same)
							.cudnnAlgoMode(cudnnAlgoMode).activation(Activation.RELU).build(),
					"pool3")
			.addLayer("conv4-2",
					new ConvolutionLayer.Builder(3, 3).stride(1, 1).nOut(256).convolutionMode(ConvolutionMode.Same)
							.cudnnAlgoMode(cudnnAlgoMode).activation(Activation.RELU).build(),
					"conv4-1")
			.addLayer("drop4", new DropoutLayer.Builder(0.5).build(), "conv4-2")
			.addLayer("pool4",
					new SubsamplingLayer.Builder(SubsamplingLayer.PoolingType.MAX).kernelSize(2, 2).build(),
					"drop4")

			.addLayer("conv5-1",
					new ConvolutionLayer.Builder(3, 3).stride(1, 1).nOut(512).convolutionMode(ConvolutionMode.Same)
							.cudnnAlgoMode(cudnnAlgoMode).activation(Activation.RELU).build(),
					"pool4")
			.addLayer("conv5-2",
					new ConvolutionLayer.Builder(3, 3).stride(1, 1).nOut(512).convolutionMode(ConvolutionMode.Same)
							.cudnnAlgoMode(cudnnAlgoMode).activation(Activation.RELU).build(),
					"conv5-1")
			.addLayer("drop5", new DropoutLayer.Builder(0.5).build(), "conv5-2")

			.addLayer("up6-1", new Upsampling2D.Builder(2).build(), "drop5")
			.addLayer("up6-2",
					new ConvolutionLayer.Builder(2, 2).stride(1, 1).nOut(256).convolutionMode(ConvolutionMode.Same)
							.cudnnAlgoMode(cudnnAlgoMode).activation(Activation.RELU).build(),
					"up6-1")
			.addVertex("merge6", new MergeVertex(), "drop4", "up6-2")
			.addLayer("conv6-1",
					new ConvolutionLayer.Builder(3, 3).stride(1, 1).nOut(256).convolutionMode(ConvolutionMode.Same)
							.cudnnAlgoMode(cudnnAlgoMode).activation(Activation.RELU).build(),
					"merge6")
			.addLayer("conv6-2",
					new ConvolutionLayer.Builder(3, 3).stride(1, 1).nOut(256).convolutionMode(ConvolutionMode.Same)
							.cudnnAlgoMode(cudnnAlgoMode).activation(Activation.RELU).build(),
					"conv6-1")

			.addLayer("up7-1", new Upsampling2D.Builder(2).build(), "conv6-2")
			.addLayer("up7-2",
					new ConvolutionLayer.Builder(2, 2).stride(1, 1).nOut(128).convolutionMode(ConvolutionMode.Same)
							.cudnnAlgoMode(cudnnAlgoMode).activation(Activation.RELU).build(),
					"up7-1")
			.addVertex("merge7", new MergeVertex(), "conv3-2", "up7-2")
			.addLayer("conv7-1",
					new ConvolutionLayer.Builder(3, 3).stride(1, 1).nOut(128).convolutionMode(ConvolutionMode.Same)
							.cudnnAlgoMode(cudnnAlgoMode).activation(Activation.RELU).build(),
					"merge7")
			.addLayer("conv7-2",
					new ConvolutionLayer.Builder(3, 3).stride(1, 1).nOut(128).convolutionMode(ConvolutionMode.Same)
							.cudnnAlgoMode(cudnnAlgoMode).activation(Activation.RELU).build(),
					"conv7-1")

			.addLayer("up8-1", new Upsampling2D.Builder(2).build(), "conv7-2")
			.addLayer("up8-2",
					new ConvolutionLayer.Builder(2, 2).stride(1, 1).nOut(64).convolutionMode(ConvolutionMode.Same)
							.cudnnAlgoMode(cudnnAlgoMode).activation(Activation.RELU).build(),
					"up8-1")
			.addVertex("merge8", new MergeVertex(), "conv2-2", "up8-2")
			.addLayer("conv8-1",
					new ConvolutionLayer.Builder(3, 3).stride(1, 1).nOut(64).convolutionMode(ConvolutionMode.Same)
							.cudnnAlgoMode(cudnnAlgoMode).activation(Activation.RELU).build(),
					"merge8")
			.addLayer("conv8-2",
					new ConvolutionLayer.Builder(3, 3).stride(1, 1).nOut(64).convolutionMode(ConvolutionMode.Same)
							.cudnnAlgoMode(cudnnAlgoMode).activation(Activation.RELU).build(),
					"conv8-1")

			.addLayer("up9-1", new Upsampling2D.Builder(2).build(), "conv8-2")
			.addLayer("up9-2",
					new ConvolutionLayer.Builder(2, 2).stride(1, 1).nOut(32).convolutionMode(ConvolutionMode.Same)
							.cudnnAlgoMode(cudnnAlgoMode).activation(Activation.RELU).build(),
					"up9-1")
			.addVertex("merge9", new MergeVertex(), "conv1-2", "up9-2")
			.addLayer("conv9-1",
					new ConvolutionLayer.Builder(3, 3).stride(1, 1).nOut(32).convolutionMode(ConvolutionMode.Same)
							.cudnnAlgoMode(cudnnAlgoMode).activation(Activation.RELU).build(),
					"merge9")
			.addLayer("conv9-2",
					new ConvolutionLayer.Builder(3, 3).stride(1, 1).nOut(32).convolutionMode(ConvolutionMode.Same)
							.cudnnAlgoMode(cudnnAlgoMode).activation(Activation.RELU).build(),
					"conv9-1")
			.addLayer("conv9-3",
					new ConvolutionLayer.Builder(3, 3).stride(1, 1).nOut(2).convolutionMode(ConvolutionMode.Same)
							.cudnnAlgoMode(cudnnAlgoMode).activation(Activation.RELU).build(),
					"conv9-2")

			.addLayer("conv10",
					new ConvolutionLayer.Builder(1, 1).stride(1, 1).nOut(1).convolutionMode(ConvolutionMode.Same)
							.cudnnAlgoMode(cudnnAlgoMode).activation(Activation.IDENTITY).build(),
					"conv9-3")
			.addLayer("output",
					new CnnLossLayer.Builder(LossFunctions.LossFunction.XENT).activation(Activation.SIGMOID)
							.build(),
					"conv10")
			.setOutputs("output");

	return graph;

}

public ModelMetaData metaData() {
	return new ModelMetaData(new int[][] { inputShape }, 1, ZooType.CNN);
}

/**
 * Change the input shape
 */

public void setInputShape(int[][] inputShape) {
	this.inputShape = inputShape[0];
}

/**
 * @param channels   - Image channel count
 * @param xDimension - x pixels
 * @param yDimension - y pixels
 */

public void setInputShape(int channels, int xDimension, int yDimension) {
	this.inputShape = new int[] { channels, xDimension, yDimension };
}

/**
 * @throws IOException
 * @file file - Where to save the network. Note: the file is in .zip format
 */

public void saveGraph(File file) throws IOException {
	ModelSerializer.writeModel(graph, file, true);
}

public void loadSavedGraph(File file) throws IOException {
	this.graph = ModelSerializer.restoreComputationGraph(file);
}

public ComputationGraph getGraph() {
	return graph;
}

public void setGraph(ComputationGraph graph) {
	this.graph = graph;
}

public DataSetIterator getDataSetIterator() {
	return dataSetIterator;
}

public void setDataSetIterator(DataSetIterator dataSetIterator) {
	this.dataSetIterator = dataSetIterator;
}

public int getFrequency() {
	return frequency;
}

public void setFrequency(int frequency) {
	this.frequency = frequency;
}

public int getMargin() {
	return margin;
}

public void setMargin(int margin) {
	this.margin = margin;
}

public int getInputSize() {
	return inputSize;
}

public void setInputSize(int inputSize) {
	this.inputSize = inputSize;
}

public float[] getOutput(MatContainer input) throws IOException {
	NativeImageLoader imageLoader = new NativeImageLoader();
	return graph.outputSingle(imageLoader.asMatrix(input.getInputMat())).toFloatVector();
}

public void trainNetwork(List<MatContainer> trainingSet, InMemoryStatsStorage ss) throws IOException {
	List<DataSet> dataSets = new ArrayList<DataSet>();

	for (MatContainer container : trainingSet) {

		Mat input = container.getInputMat();
		Mat output = container.getOutputMat();

		System.out.println(input.cols());
		
		int numCols = (int) Math.ceil((double) (input.cols() - margin * 2) / inputSize);
		int numRows = (int) Math.ceil((double) (input.rows() - margin * 2) / inputSize);

		for (int y = 0; y < numRows; y++) {

			for (int x = 0; x < numCols; x++) {

				int xLeft = (int) Math.round(x * inputSize) + margin;
				int yTop = (int) Math.round(y * inputSize) + margin;
				if (xLeft + inputSize > input.cols() - margin) {
					xLeft = input.cols() - margin - inputSize;
				}
				if (yTop + inputSize > input.rows() - margin) {
					yTop = input.rows() - margin - inputSize;
				}

				int xRight = xLeft + inputSize;
				int yBottom = yTop + inputSize;

				Rect rect = new Rect(xLeft, yTop, xRight - xLeft, yBottom - yTop);
				Rect rectLabel = new Rect(xLeft, yTop, inputSize, inputSize);

				Mat inputSmall = new Mat(input, rect);
				Mat outputSmall = new Mat(output, rectLabel);

				dataSets.add(convertImage(inputSmall, outputSmall));
			}
		}

	}

	DataSetIterator iterator = new ListDataSetIterator<>(dataSets);
	
    graph.setListeners(new StatsListener(ss, 1), new ScoreIterationListener(1),  new EvaluativeListener(iterator, 1, InvocationType.EPOCH_END));

	graph.fit(iterator, 10);
}

private DataSet convertImage(Mat input, Mat output) throws IOException {
	NativeImageLoader imageLoader = new NativeImageLoader();

	INDArray indArrayInput = imageLoader.asMatrix(input);
	INDArray indArrayOutput = imageLoader.asMatrix(output);
	

	return new DataSet(indArrayInput.mul(1 / 255f).add(-.5f), indArrayOutput.gte(1.00f));
}

public void score(Mat input, Mat output) throws IOException {
	DataSet dataIter = convertImage(input, output);
	graph.score(dataIter);
}

}

13:39:05.420 [main] INFO org.nd4j.linalg.factory.Nd4jBackend - Loaded [CpuBackend] backend
13:39:06.902 [main] INFO org.nd4j.nativeblas.NativeOpsHolder - Number of threads used for NativeOps: 4
13:39:07.092 [main] INFO org.nd4j.nativeblas.Nd4jBlas - Number of threads used for BLAS: 4
13:39:07.100 [main] INFO org.nd4j.linalg.api.ops.executioner.DefaultOpExecutioner - Backend used: [CPU]; OS: [Windows 10]
13:39:07.100 [main] INFO org.nd4j.linalg.api.ops.executioner.DefaultOpExecutioner - Cores: [8]; Memory: [1.7GB];
13:39:07.100 [main] INFO org.nd4j.linalg.api.ops.executioner.DefaultOpExecutioner - Blas vendor: [MKL]
13:39:07.413 [main] INFO org.deeplearning4j.nn.graph.ComputationGraph - Starting ComputationGraph with WorkspaceModes set to [training: ENABLED; inference: ENABLED], cacheMode set to [NONE]
13:39:10.261 [main] DEBUG play.api.libs.concurrent.ActorSystemProvider - Starting application default Akka system: application
13:39:10.419 [main] INFO play.api.Play - Application started (Prod)
13:39:10.678 [main] INFO play.core.server.NettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
13:39:10.680 [main] INFO org.deeplearning4j.ui.play.PlayUIServer - DL4J UI Server started at http://localhost:9000
13:39:10.681 [Thread-3] DEBUG org.deeplearning4j.ui.play.PlayUIServer - PlayUIServer.StatsEventRouterRunnable started
13:39:10.682 [main] INFO org.deeplearning4j.ui.play.PlayUIServer - StatsStorage instance attached to UI: InMemoryStatsStorage(uid=c9fc6045)
2049
13:39:55.246 [main] INFO org.deeplearning4j.optimize.listeners.ScoreIterationListener - Score at iteration 0 is 44248.37180777664
13:40:34.688 [main] INFO org.deeplearning4j.optimize.listeners.ScoreIterationListener - Score at iteration 1 is 287123.9349820905
13:41:13.817 [main] INFO org.deeplearning4j.optimize.listeners.ScoreIterationListener - Score at iteration 2 is 293399.83497858734
13:41:54.414 [main] INFO org.deeplearning4j.optimize.listeners.ScoreIterationListener - Score at iteration 3 is 323728.43497509265
13:42:35.241 [main] INFO org.deeplearning4j.optimize.listeners.ScoreIterationListener - Score at iteration 4 is 313148.4349716122
13:43:14.333 [main] INFO org.deeplearning4j.optimize.listeners.ScoreIterationListener - Score at iteration 5 is 327679.8099681113
13:43:54.947 [main] INFO org.deeplearning4j.optimize.listeners.ScoreIterationListener - Score at iteration 6 is 339310.93496460834
13:44:33.644 [main] INFO org.deeplearning4j.optimize.listeners.ScoreIterationListener - Score at iteration 7 is 373948.9349611043
13:45:12.618 [main] INFO org.deeplearning4j.optimize.listeners.ScoreIterationListener - Score at iteration 8 is 273551.60995761346
13:45:53.348 [main] INFO org.deeplearning4j.optimize.listeners.ScoreIterationListener - Score at iteration 9 is 375239.2349541071
13:46:32.953 [main] INFO org.deeplearning4j.optimize.listeners.ScoreIterationListener - Score at iteration 10 is 321193.80995060573
13:47:11.529 [main] INFO org.deeplearning4j.optimize.listeners.ScoreIterationListener - Score at iteration 11 is 327040.43494710966
13:47:49.836 [main] INFO org.deeplearning4j.optimize.listeners.ScoreIterationListener - Score at iteration 12 is 308502.43494360417
13:48:28.401 [main] INFO org.deeplearning4j.optimize.listeners.ScoreIterationListener - Score at iteration 13 is 331263.23494011443
13:49:07.560 [main] INFO org.deeplearning4j.optimize.listeners.ScoreIterationListener - Score at iteration 14 is 322649.70993664186
13:49:46.175 [main] INFO org.deeplearning4j.optimize.listeners.ScoreIterationListener - Score at iteration 15 is 340251.6349331493
13:49:51.141 [main] INFO org.deeplearning4j.optimize.listeners.ScoreIterationListener - Score at iteration 16 is 304804.4246483118
13:49:51.143 [main] INFO org.deeplearning4j.optimize.listeners.EvaluativeListener - Starting evaluation nr. 1
Exception in thread “main” java.lang.IllegalStateException: Rank is [4]; columns() call is not valid
at org.nd4j.linalg.api.ndarray.BaseNDArray.columns(BaseNDArray.java:4835)
at org.nd4j.evaluation.classification.Evaluation.eval(Evaluation.java:370)
at org.nd4j.evaluation.classification.Evaluation.eval(Evaluation.java:351)
at org.nd4j.evaluation.BaseEvaluation.eval(BaseEvaluation.java:107)
at org.deeplearning4j.nn.graph.ComputationGraph.doEvaluationHelper(ComputationGraph.java:4077)
at org.deeplearning4j.nn.graph.ComputationGraph.doEvaluationHelper(ComputationGraph.java:4017)
at org.deeplearning4j.nn.graph.ComputationGraph.doEvaluation(ComputationGraph.java:3975)
at org.deeplearning4j.nn.graph.ComputationGraph.doEvaluation(ComputationGraph.java:3962)
at org.deeplearning4j.optimize.listeners.EvaluativeListener.invokeListener(EvaluativeListener.java:243)
at org.deeplearning4j.optimize.listeners.EvaluativeListener.onEpochEnd(EvaluativeListener.java:213)
at org.deeplearning4j.nn.graph.ComputationGraph.fit(ComputationGraph.java:1073)
at org.deeplearning4j.nn.graph.ComputationGraph.fit(ComputationGraph.java:999)
at org.deeplearning4j.nn.graph.ComputationGraph.fit(ComputationGraph.java:987)
at com.asinm.pix2net.neuralnetwork.MSINeuralNetwork.trainNetwork(MSINeuralNetwork.java:405)
at com.asinm.pix2net.neuralnetwork.MSINeuralNetwork.main(MSINeuralNetwork.java:101)

At first glance it seems like you have a datset iterator issue. Also I really dont understand what your trying to do by breaking up the pictures.

If I were you I would temporarily comment out the .fit method and try this

datatset = iterator.next
List a = net.feedForwardToLayer(10, d.getFeatures());
network.fit(datset.getfeatures, datset.getfeatures)

Drop some debugging points and make sure your arrays are the right shape and values as you debug

Thank you for the quick reply!

I am looking through trying to figure out what you mean by dataset iterator issue. I believe graph.fit() is supposed to be able to handle an iterator like I had it. And the code trains for 16 iterations before crashing.

I am trying to modify the code to include your suggestion.

line 2: “List a = net.feedForwardToLayer(10, d.getFeatures());”
I am a little confused by line 2 of your suggestion though. There is no feedForwardToLayer() function defined for a network as far as I can tell, and then “List a” is never used. How should I use this?

line 3: “network.fit(datset.getfeatures, datset.getfeatures)”
Also, the next line did you mean graph.fit(dataset.getFeatures(), 10)? Or should both of those arguments be the same?

I am trying to debug to see why suddenly the NDarray would change to rank 4. All I am doing is feeding in 64 images that are 256 x 256, and it trains up to iteration 16, and then suddenly deep in dl4j columns() is being called with a rank 4 NDarray.
Could that problem possibly be because I am not formatting the input correctly here? :

private DataSet convertImage(Mat input, Mat output) throws IOException {
NativeImageLoader imageLoader = new NativeImageLoader();

	INDArray indArrayInput = imageLoader.asMatrix(input);
	INDArray indArrayOutput = imageLoader.asMatrix(output);
	

	return new DataSet(indArrayInput.mul(1 / 255f).add(-.5f), indArrayOutput.gte(1.00f));
} 

Thank you in advance for any help or suggestions.

Sorry, I just quickly copied some code into there without thinking too much. You are using a graph and your output or method calls may be different than what I pasted. But your have a mismatch between what your iterator is psuhing out and what your network is expecting as a certain point

graph.fit obfuscates so much of the functionality. I recommend you set it aside in order to debug. But you are right that It will work once you find the bug. If you call dataset.feature() for a color image I believe it will always be rank 4 (minibatch, RGB, width, height) so im not sure whats surprising about that

Truthfully you pasted a big wall of code that I dont have the time to sort through it. My comments are more to give you a strategy to find the error. Break down each step and visually examine the arrays in the dataset returned from iterator.next() using debuging points. Then don’t bother trying to train the network. just call feedforward and that list output will show you the output of each layer on the feedforward pass so you can examine the data flowing from your iterator through the network.

thats what I would try at least. hope it helps