很明显,我不能只为我为TensorFlow编写的自定义操作复制并粘贴代码,然后在Lite版本中使用它
我的代码引用了主要代码的内容:
#include "tensorflow/core/framework/op.h"
#include "tensorflow/core/framework/shape_inference.h"
#include "tensorflow/core/framework/op_kernel.h"
using namespace tensorflow;
和
Status MyAddGrad(const Scope& scope, const Operation& op,
const std::vector<Output>& grad_inputs,
std::Vector<Output>* grad_outputs){
我在TensorFlow Lite中找不到自定义操作的完整样本(甚至最少)。只有我应该修改哪些文件才能将Lite编译为'.aar'
答案 0 :(得分:0)
Custom operators指南页面显示了如何在TFLite中实现package com.example.attendanceapp;
import android.content.Context;
import android.os.AsyncTask;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.SQLOutput;
public class BackgroundWorker extends AsyncTask<String,Void,String> {
Context context;
private String id;
BackgroundWorker (Context ctx)
{
context=ctx;
}
@Override
protected String doInBackground(String... params) {
String conn_url="http://identifyme.co.nf/app.php?CDATE="+"d20_5_2019";
try {
URL url= new URL(conn_url);
HttpURLConnection httpURLConnection= (HttpURLConnection)url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
InputStream inputStream=httpURLConnection.getInputStream();
BufferedReader bufferedReader= new BufferedReader(new InputStreamReader(inputStream,"iso-8859-1"));
String result="";
String line="";
bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
return result;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(String result) {
//super.onPostExecute();
}
@Override
protected void onProgressUpdate(Void... values) {
//super.onProgressUpdate(values);
}
}
This is a java classby the name of BackgroundWorker , I am calling this in another class on OnCreate of that class :
BackgroundWorker backgroundWorker =new BackgroundWorker(this);
backgroundWorker.execute(a,null,heightval);
自定义操作的规范示例。
您必须为op定义Sin
和Prepare
函数,如here所示,然后使用Eval
调用让OpResolver知道。