.lite和格式(TensorFlow 格式)之间有什么区别.tflite?如果没有区别,为什么会有两个?
除了这个问题之外,我似乎无法将带有.lite扩展文件的模型上传到 Firebase ML 套件。原因可能是什么?
当我研究 Tensorflow Lite 时,我发现自定义操作将作为“flex op”导出,而不是作为本机导出。我不明白什么是“flex op”,什么是“native”。谢谢你!
与我的问题相关的代码位于https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/toco/tflite/export.cc#L368
预先感谢您的支持。
我试图在 .tflite U-net 神经网络上进行推理后获取张量的输出。我使用 Tensorflow lite 图像分类代码作为基线。
我需要调整代码以执行分段任务。我的问题是如何访问推断模型的输出(128x128x1)并将结果写入图像?
我已经调试了代码并探索了许多不同的方法。不幸的是,我对 C++ 语言没有信心。我发现命令:interpreter->typed_output_tensor<float>(0)应该是我需要的,也在这里引用:https: //www.tensorflow.org/lite/guide/inference#loading_a_model。但是,我无法访问网络生成的 128x128 张量。
有趣的部分在这里(第 217 -224 行):
const float threshold = 0.001f;
std::vector<std::pair<float, int>> top_results;
int output = interpreter->outputs()[0];
TfLiteIntArray* output_dims = interpreter->tensor(output)->dims;
// assume output dims to be something like (1, 1, ... ,size)
auto output_size = output_dims->data[output_dims->size - 1];
Run Code Online (Sandbox Code Playgroud)
我期望保存在图像中的值或保存输出张量的替代方法
我有一个 Keras 模型,想在 Coral Edge TPU 设备上运行。为此,它需要是具有完整整数量化的 Tensorflow Lite 模型。我能够将模型转换为 TFLite 模型:
model.save('keras_model.h5')
converter = tf.lite.TFLiteConverter.from_keras_model_file("keras_model.h5")
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)
Run Code Online (Sandbox Code Playgroud)
但是当我运行时edgetpu_compiler converted_model.tflite,我收到此错误:
Edge TPU Compiler version 2.0.267685300
Invalid model: converted_model.tflite
Model not quantized
Run Code Online (Sandbox Code Playgroud)
这是因为我需要量化模型,但我不知道该怎么做。我发现这个页面告诉我如何做到这一点,但它希望我制作一个输入数据生成器。这是它提供的示例:
Edge TPU Compiler version 2.0.267685300
Invalid model: converted_model.tflite
Model not quantized
Run Code Online (Sandbox Code Playgroud)
如何调整此代码以处理我的输入数据?从哪里来num_calibration_steps?有一个更好的方法吗?(我看到了参考tf.contrib.tpu.keras_to_tpu_model但它已被弃用)
我需要从源代码构建 TensorFlowLite Swift Framework/cocoapod,然后在 Swift 项目之一中使用它而不是原始框架。
下载代码并按照说明进行操作,但在少数情况下没有成功:
1) https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/experimental/swift
a) python 配置.py
b) CocoaPods 开发人员不适用,因为它不从本地 TensofFlow 文件夹获取源代码(或者我错了?)
c) Bazel 开发人员我所做的:
bazel build tensorflow/lite/experimental/swift:TensorFlowLite
bazel test tensorflow/lite/experimental/swift:Tests --swiftcopt=-enable-testing
最终
generate_xcodeproj.sh --genconfig tensorflow/lite/experimental/swift/TensorFlowLite.tulsiproj:TensorFlowLite --outputfolder ~/path/to/generated/TensorFlowLite.xcodeproj
结果我得到了一个带有 libtensorflow-lite-experimental-swift-TensorFlowLite.a 和一些idx文件的项目。它编译并看到 .a 文件(但应用程序和测试由于各种原因都没有编译),并且我不太明白如何将 .a lib 与 Swift 文件一起使用,因为没有模块/标头等. 文件。
所有这些练习完成后,就可以TensorFlowLiteSwift.podspec在 TensorFlow 的根目录和experimental/Swift文件夹中找到。它仍然取决于,TensorFlowLiteC如果我通过路径参数在另一个项目中引用这个 podspec,我可以这样做,import TensorFlowLiteC但不能import TensorFlowLiteSwift/import TensorFlowLite并且我相信 TensorFlowLiteC 仍然是从互联网上获取的,而不是本地的。
2)自定义框架路径: https ://firebase.google.com/docs/ml-kit/ios/use-custom-tflite
这里有几个问题:
a)如果我尝试仅使用内部添加了tensorflow_lite.framework的项目,那么我无法在Swift文件中引用TensorFlowLite/等。TensorFlowLiteCb) 如果我尝试遵循创建本地 Pod …
我有 .pickle 文件,它由面部编码数组组成,现在我想将其转换为 .tflite 扩展文件。我该怎么做?提前致谢!回答将不胜感激
computer-vision python-3.x deep-learning tensorflow tensorflow-lite
我有一个 SSD tflite 检测模型,正在台式计算机上使用 Python 运行。就目前而言,我的下面的脚本将单个图像作为推理的输入,并且运行良好:
# Load TFLite model and allocate tensors.
interpreter = tf.lite.Interpreter(model_path="model.tflite")
interpreter.allocate_tensors()
img_resized = Image.open(file_name)
input_data = np.expand_dims(img_resized, axis=0)
input_data = (np.float32(input_data) - input_mean) / input_std
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
interpreter.set_tensor(input_details[0]['index'], input_data)
interpreter.invoke()
output_data = interpreter.get_tensor(output_details[0]['index'])
Run Code Online (Sandbox Code Playgroud)
如何对 .mp4 视频作为输入进行推理?
是否也可以从该视频上检测到的对象中绘制边界框?
尝试运行代码实验室: https://codelabs.developers.google.com/codelabs/recognize-flowers-with-tensorflow-on-android/#6
我已经开发了自己的文件和列表文件,尽管当我开始通过 Android 运行它时似乎收到此错误:
java.lang.IllegalArgumentException: Label number 6 mismatch the shape on axis 1
然后它将我链接到这部分代码:
Map<String, Float> labeledProbability =
new TensorLabel(labels, probabilityProcessor.process(outputProbabilityBuffer))
.getMapWithFloatValue();
Trace.endSection();
Run Code Online (Sandbox Code Playgroud)
这是在分类结果部分
public List<Recognition> recognizeImage(final Bitmap bitmap, int sensorOrientation) {
// Logs this method so that it can be analyzed with systrace.
Trace.beginSection("recognizeImage");
Trace.beginSection("loadImage");
long startTimeForLoadImage = SystemClock.uptimeMillis();
inputImageBuffer = loadImage(bitmap, sensorOrientation);
long endTimeForLoadImage = SystemClock.uptimeMillis();
Trace.endSection();
LOGGER.v("Timecost to load the image: " + (endTimeForLoadImage - startTimeForLoadImage));
// Runs the inference call.
Trace.beginSection("runInference");
long startTimeForReference = …Run Code Online (Sandbox Code Playgroud) 我有使用预训练的 bert 模型构建的语义搜索引擎的代码。我想将此模型转换为 tflite,以便将其部署到 google mlkit。我想知道如何转换它。我想知道是否有可能将其转换为 tflite。这可能是因为它在官方tensorflow网站上提到: https: //www.tensorflow.org/lite/convert。但我不知道从哪里开始
代码:
from sentence_transformers import SentenceTransformer
# Load the BERT model. Various models trained on Natural Language Inference (NLI) https://github.com/UKPLab/sentence-transformers/blob/master/docs/pretrained-models/nli-models.md and
# Semantic Textual Similarity are available https://github.com/UKPLab/sentence-transformers/blob/master/docs/pretrained-models/sts-models.md
model = SentenceTransformer('bert-base-nli-mean-tokens')
# A corpus is a list with documents split by sentences.
sentences = ['Absence of sanity',
'Lack of saneness',
'A man is eating food.',
'A man is eating a piece of bread.',
'The girl is carrying a baby.',
'A man …Run Code Online (Sandbox Code Playgroud) 我将 h5 文件转换为 tflite。这个h5文件是ml5 Json模型。我刚刚自己转换成h5文件。但它不适用于错误代码。
Windows10、Python 3.6.8、tfv2.0.0
代码:
import tensorflow as tf
model=tf.keras.models.load_model("E:\h5\outputs\model.h5")
converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.experimental_new_converter = True
tflite_model = converter.convert()
open("E:\h5\converted_model.tflite", "wb").write(tflite_model)
Run Code Online (Sandbox Code Playgroud)
我用这些代码转换了文件
这个模型文件被放入我的应用程序中。
错误代码:
[+14766 ms] D/ViewRootImpl@454dd0a[MainActivity]( 1610): ViewPostIme pointer 0
[ +133 ms] D/ViewRootImpl@454dd0a[MainActivity]( 1610): ViewPostIme pointer 1
[ +13 ms] I/tflite ( 1610): Initialized TensorFlow Lite runtime.
[ +36 ms] I/flutter ( 1610): success
[ +12 ms] I/CameraManagerGlobal( 1610): Camera 0 facing CAMERA_FACING_BACK state now
CAMERA_STATE_OPEN for client com.example.examplerealtime API Level 2
[ …Run Code Online (Sandbox Code Playgroud) tensorflow-lite ×10
tensorflow ×8
python ×3
android ×2
c++ ×1
cocoapods ×1
firebase ×1
flutter ×1
inference ×1
ios ×1
java ×1
keras ×1
python-3.x ×1
swift ×1
tpu ×1