2023年12月29日

android load tensorflow model from raw

 


   private   Interpreter load_model(Context context,int id){
 
        byte[] bytes= Document_read.load_from_raw_bytes(context,id);
        ByteBuffer bb = ByteBuffer.allocateDirect(bytes.length);
        bb.order(ByteOrder.nativeOrder());
        bb.put(bytes);
 
        Interpreter.Options options = new Interpreter.Options();
        options.addDelegate(new GpuDelegate());
        Interpreter interpreter = new Interpreter(bb,options);
        interpreter.allocateTensors();
        return  interpreter;
    }

沒有留言:

張貼留言