Search in sources :

Example 1 with TorchGeneric

use of deepboof.io.torch7.struct.TorchGeneric in project BoofCV by lessthanoptimal.

the class ImageClassifierResNet method loadModel.

@Override
public void loadModel(File path) throws IOException {
    String name = String.format("resnet/resnet-%d.t7", resnetID);
    List<TorchObject> list = new ParseBinaryTorch7().parse(new File(path, name));
    TorchGeneric torchSequence = (TorchGeneric) list.get(0);
    // mean = torchListToArray( (TorchList)torchNorm.get("mean"));
    // stdev = torchListToArray( (TorchList)torchNorm.get("std"));
    SequenceAndParameters<Tensor_F32, Function<Tensor_F32>> seqparam = ConvertTorchToBoofForward.convert(torchSequence);
    System.out.println("Bread here");
}
Also used : TorchGeneric(deepboof.io.torch7.struct.TorchGeneric) Function(deepboof.Function) TorchObject(deepboof.io.torch7.struct.TorchObject) ParseBinaryTorch7(deepboof.io.torch7.ParseBinaryTorch7) Tensor_F32(deepboof.tensors.Tensor_F32) File(java.io.File)

Example 2 with TorchGeneric

use of deepboof.io.torch7.struct.TorchGeneric in project BoofCV by lessthanoptimal.

the class ImageClassifierNiNImageNet method loadModel.

@Override
public void loadModel(File directory) throws IOException {
    List<TorchObject> list = new ParseBinaryTorch7().parse(new File(directory, "nin_bn_final.t7"));
    TorchGeneric torchSequence = ((TorchGeneric) list.get(0)).get("model");
    TorchGeneric torchNorm = torchSequence.get("transform");
    mean = torchListToArray((TorchList) torchNorm.get("mean"));
    stdev = torchListToArray((TorchList) torchNorm.get("std"));
    SequenceAndParameters<Tensor_F32, Function<Tensor_F32>> seqparam = ConvertTorchToBoofForward.convert(torchSequence);
    network = seqparam.createForward(3, imageCrop, imageCrop);
    tensorOutput = new Tensor_F32(WI(1, network.getOutputShape()));
    TorchList torchCategories = (TorchList) new ParseAsciiTorch7().parse(new File(directory, "synset.t7")).get(0);
    categories.clear();
    for (int i = 0; i < torchCategories.list.size(); i++) {
        categories.add(((TorchString) torchCategories.list.get(i)).message);
    }
}
Also used : Function(deepboof.Function) ParseBinaryTorch7(deepboof.io.torch7.ParseBinaryTorch7) Tensor_F32(deepboof.tensors.Tensor_F32) File(java.io.File) ParseAsciiTorch7(deepboof.io.torch7.ParseAsciiTorch7)

Aggregations

Function (deepboof.Function)2 ParseBinaryTorch7 (deepboof.io.torch7.ParseBinaryTorch7)2 Tensor_F32 (deepboof.tensors.Tensor_F32)2 File (java.io.File)2 ParseAsciiTorch7 (deepboof.io.torch7.ParseAsciiTorch7)1 TorchGeneric (deepboof.io.torch7.struct.TorchGeneric)1 TorchObject (deepboof.io.torch7.struct.TorchObject)1