use of com.simiacryptus.mindseye.layers.java.ImgBandSelectLayer in project MindsEye by SimiaCryptus.
the class EncodingUtil method downExplodeTensors.
/**
* Down explode tensors stream.
*
* @param stream the stream
* @param factor the factor
* @return the stream
*/
@Nonnull
public static Stream<Tensor[]> downExplodeTensors(@Nonnull final Stream<Tensor[]> stream, final int factor) {
if (0 >= factor)
throw new IllegalArgumentException();
if (-1 == factor)
throw new IllegalArgumentException();
return 1 == factor ? stream : stream.flatMap(tensor -> IntStream.range(0, factor * factor).mapToObj(subband -> {
@Nonnull final int[] select = new int[tensor[1].getDimensions()[2]];
final int offset = subband * select.length;
for (int i = 0; i < select.length; i++) {
select[i] = offset + i;
}
@Nonnull final PipelineNetwork network = new PipelineNetwork();
network.add(new ImgReshapeLayer(factor, factor, false));
network.add(new ImgBandSelectLayer(select));
@Nullable final Tensor result = network.eval(tensor[1]).getData().get(0);
return new Tensor[] { tensor[0], result };
}));
}
Aggregations