-
I am looking at chapter 5.2 of the online book. We have the following code: NDManager manager = NDManager.newBaseManager();
NDArray x = manager.randomUniform(0, 1, new Shape(2, 4));
Model model = Model.newInstance("lin-reg");
SequentialBlock net = new SequentialBlock();
net.add(Linear.builder().setUnits(8).build());
net.add(Activation.reluBlock());
net.add(Linear.builder().setUnits(1).build());
net.setInitializer(new NormalInitializer());
net.initialize(manager, DataType.FLOAT32, x.getShape());
model.setBlock(net);
Predictor<NDList, NDList> predictor = model.newPredictor(new NoopTranslator());
predictor.predict(new NDList(x)).singletonOrThrow(); // forward computation I am assuming that given the However, looking at the example the input is Apologies if this is simpleton's question. TIA |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The input is not specified when creating the linear blocks in net. Because inputs can be computed, we thought it would be too much work to have to type them for every block. So, the 8 you are looking at is the output of the first linear block. The input is not determined until the call to |
Beta Was this translation helpful? Give feedback.
The input is not specified when creating the linear blocks in net. Because inputs can be computed, we thought it would be too much work to have to type them for every block. So, the 8 you are looking at is the output of the first linear block.
The input is not determined until the call to
net.initialize
. At this point, it determines the input is of size 4 (with batch size 2) usingx.getShape()