I need to convert my 3-D tensor containing RGB image to BGR.
All the sources I've found on the web use python and they refer to operations that are either absent or different on java:
Stack
and Unstack
operations are actually called as they have previously been on the other platforms, that is, Pack
and Unpack
. *
So, to perform the requested operation of transforming a Tensor representing an image in RGB to an image in BGR, the unstack/stack way can be followed.
public <T> Output<T> rgbToBgr(Output<T> input) {
return stackReverted(unstack(input));
}
// where g is Graph
public <T> Output<T>[] unstack(Output<T> input) {
return (Output<T>[]) g.opBuilder("Unpack", "Unpack")
.addInput(input)
.setAttr("axis", -1)
.setAttr("num", 3)
.build().outputList(0, 3);
}
public <T> Output<T> stackReverted(Output<T>[] input){
GraphOperationBuilder graphOperationBuilder = g.opBuilder("Pack", "Pack")
.setAttr("axis", -1);
Output<T>[] newInput = Arrays.copyOf(input, input.length);
for (int i = 0; i < input.length; i++)
newInput[i] = input[input.length - 1 - i];
graphOperationBuilder.addInputList(newInput);
return graphOperationBuilder.build().output(0);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.