简体   繁体   中英

Tensorflow on Java: how to perform RGB to BGR operation?

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:

  1. reverse does not accept an index but a boolean as second input
  2. I've found the stack/unstack method, but unstack does not exist

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);
    }
  • There is no trace anywhere. If anybody can find documentation for Java, please post it.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM