tensorflow

tflite quantized inference very slow

◇◆丶佛笑我妖孽 提交于 2021-01-27 04:14:36
问题 I am trying to convert a trained model from checkpoint file to tflite . I am using tf.lite.LiteConverter . The float conversion went fine with reasonable inference speed. But the inference speed of the INT8 conversion is very slow. I tried to debug by feeding in a very small network. I found that inference speed for INT8 model is generally slower than float model. In the INT8 tflite file, I found some tensors called ReadVariableOp, which doesn't exist in TensorFlow's official mobilenet tflite

Tensorflow - Retrieve each character in a string tensor

限于喜欢 提交于 2021-01-27 04:05:22
问题 I'm trying to retrieve the characters in a string tensor for character level prediction. The ground truths are words where each character has an id in dictionary. I have a tensor corresponding to the length of the string. Now, I have to get each character in the string tensor. After checking the related posts, a simple retrieval can be as follows. Example string is "This" a= tf.constant("This",shape=[1]) b=tf.string_split(a,delimiter="").values #Sparse tensor has the values array which stores

Tensorflow - Retrieve each character in a string tensor

不打扰是莪最后的温柔 提交于 2021-01-27 04:03:52
问题 I'm trying to retrieve the characters in a string tensor for character level prediction. The ground truths are words where each character has an id in dictionary. I have a tensor corresponding to the length of the string. Now, I have to get each character in the string tensor. After checking the related posts, a simple retrieval can be as follows. Example string is "This" a= tf.constant("This",shape=[1]) b=tf.string_split(a,delimiter="").values #Sparse tensor has the values array which stores

Tensorflow - Retrieve each character in a string tensor

吃可爱长大的小学妹 提交于 2021-01-27 04:01:57
问题 I'm trying to retrieve the characters in a string tensor for character level prediction. The ground truths are words where each character has an id in dictionary. I have a tensor corresponding to the length of the string. Now, I have to get each character in the string tensor. After checking the related posts, a simple retrieval can be as follows. Example string is "This" a= tf.constant("This",shape=[1]) b=tf.string_split(a,delimiter="").values #Sparse tensor has the values array which stores

Memory leak when running python script from C++

我们两清 提交于 2021-01-27 03:56:28
问题 The following minimal example of calling a python function from C++ has a memory leak on my system: script.py : import tensorflow def foo(param): return "something" main.cpp : #include "python3.5/Python.h" #include <iostream> #include <string> int main() { Py_Initialize(); PyRun_SimpleString("import sys"); PyRun_SimpleString("if not hasattr(sys,'argv'): sys.argv = ['']"); PyRun_SimpleString("sys.path.append('./')"); PyObject* moduleName = PyUnicode_FromString("script"); PyObject* pModule =

Memory leak when running python script from C++

拟墨画扇 提交于 2021-01-27 03:56:28
问题 The following minimal example of calling a python function from C++ has a memory leak on my system: script.py : import tensorflow def foo(param): return "something" main.cpp : #include "python3.5/Python.h" #include <iostream> #include <string> int main() { Py_Initialize(); PyRun_SimpleString("import sys"); PyRun_SimpleString("if not hasattr(sys,'argv'): sys.argv = ['']"); PyRun_SimpleString("sys.path.append('./')"); PyObject* moduleName = PyUnicode_FromString("script"); PyObject* pModule =

WebAssembly 在 AI 推理中的作用

荒凉一梦 提交于 2021-01-27 02:39:38
文中带有大量链接,点击阅读原文,查看文中所附资源 阅读本教程后,你将能够独立构建一个用于图像分类的 Serverless 应用,比如这个 能识别食物的网页 。你也可以在腾讯云上试试 更多 TensorFlow 函数 。 人工智能(AI)正在改变我们的生活。但是,AI 应用所需要的,远远不止算法、数据科学和大数据训练模型。据估计,在生产环境中,95% 的人工智能计算都是用于推理的。使用人工智能推理服务的最佳平台是公共云或边缘云 ,因为云能够提供丰富的计算能力、高效安全的模型管理,以及更快的 5G 互联网连接。 把 AI 模型放到云上的生产环境,比如腾讯云,我们有几种方法。 你可以启动一个虚拟机服务器,并使用 TensorFlow Server 等工具运行 AI 模型。这种 DIY 方法需要对人工智能和操作系统都有深入的操作知识,而且通常相当昂贵,因为你需要为闲置资源付费。 你也可以使用公有云的 AI SaaS 服务上传自己的模型,然后使用 web UI 或 API 上传数据进行推理。这很容易,但不太灵活。会受到 SaaS 所支持的模型、配置和数据预处理/后处理的种类的限制。 但是对于大多数开发者来说,在自己的应用程序中使用 AI 推理需要灵活性与易用性兼备。也就是说,大部分的应用需求介于 DIY 和 AI SaaS 之间。这是为什么在生产环境中部署 AI 模型是一件很有挑战的事。

Could Keras prefetch data like tensorflow Dataset?

痞子三分冷 提交于 2021-01-27 01:39:10
问题 In TensorFlow's Dataset API, we can use dataset.prefetch(buffer_size=xxx) to preload other batches' data while GPU is processing the current batch's data, therefore, I can make full use of GPU. I'm going to use Keras, and wonder if keras has a similar API for me to make full use of GPU, instead of serial execution: read batch 0->process batch 0->read batch 1-> process batch 1-> ... I briefly looked through the keras API and did not see a description of the prefetch. 回答1: If you call fit

python列表冒号逗号常规用法

邮差的信 提交于 2021-01-26 18:58:45
列表中冒号用法 L = (1,2,3,4,5,6) 取第i个元素:L[i] 取倒数第i个元素:L[-i] 取第i到第j个元素(不包含第k个):L[i:j] 取第i个元素以后剩下的元素:L[i:] 取前i个元素:L[:i] 取后i个元素(i不能大于L的长度):L[-i:] import numpy as np L = ( 1 , 2 , 3 , 5 , 8 , 13 , 21 ) i, j = 3 , 5 print (L[i]) #取第i个元素 print (L[-i]) #取倒数第i个元素 print (L[i:j]) #取第i到第j个元素(不包含第k个) print (L[:i]) #取前i个元素 print (L[-i:]) #取后i个元素 print (L[:]) #取所有元素 结果如下: 逗号 1.shape属性 shape属性是numpy或者tensorflow中关于矩阵的一个维度元组,假如矩阵matrix的维度是N,则shape的长度也是N,第i个维度的值代表在第i个维度上的大小。 举个栗子,矩阵A=np.array([[1,2,3],[4,5,6]])。那么A.shape=(2,3),即A.shape[0] = 2,A.shape[1] = 3。 2.取值 取第m行第n列的值:A[m,n] 取第m行的所有值:A[m, :] 取第n列的所有值:A[:, n]

What if Batch Normalization is used in training mode when testing?

二次信任 提交于 2021-01-26 18:36:50
问题 Batch Normalization has different behavior in training phase and testing phase. For example, when using tf.contrib.layers.batch_norm in tensorflow, we should set different value for is_training in different phase. My qusetion is: what if I still set is_training=True when testing? That is to say what if I still use the training mode in testing phase? The reason why I come up with this question is that, the released code of both Pix2Pix and DualGAN don't set is_training=False when testing. And