tensorflow

tensorflow lite(tflite) invoke error after resize the input dimension

折月煮酒 提交于 2021-02-08 10:45:29
问题 I am using mobilenet_ssd.tflite as the mode from the official tensorflow github. Code below: int input = interpreter->inputs()[0]; interpreter->ResizeInputTensor(input, sizes); This will cause error when calling : interpreter->AllocateTensors() If I comment out the interpreter->ResizeInputTensor(input, sizes); Then every thing is fine. Any suggestions? Another question that I asked: change the input image size for mobilenet_ssd using tensorflow 回答1: ResizeInputTensor is restricted by the

Keras loss becomes nan only at epoch end

寵の児 提交于 2021-02-08 10:30:21
问题 I am observing some strange behavior from Keras. I am training a small model where the training loss becomes nan only at the end of the first epoch. So if I have 100 batches, and I terminate training at batch 99, then resume for another 99 it trains fine. Otherwise, once it reaches the end of an epoch it always returns nan. I am using a custom loss function: def corr(x, y): xc = x - K.mean(x) yc = y - K.mean(y) r_num = K.mean(xc*yc) r_den = K.std(x)*K.std(y) return r_num/r_den And I have

Load a Tensorflow graph once and use it multiple times?

二次信任 提交于 2021-02-08 10:28:57
问题 I have a TF model that was saved with the tf.train.Saver class, and so I have the .meta file, the data-00000-of-00001 file, the index file and the checkpoint file. I use it for inference like this : graph_num = tf.Graph() with graph_num.as_default(): sess = tf.Session() with sess.as_default(): new_saver = tf.train.import_meta_graph('{}.meta'.format(model_path), clear_devices=True) new_saver.restore(sess, ('{}'.format(model_path))) sess.run(tf.tables_initializer()) arr_placeholder = graph_num

Soft actor critic with discrete action space

[亡魂溺海] 提交于 2021-02-08 10:27:22
问题 I'm trying to implement the soft actor critic algorithm for discrete action space and I have trouble with the loss function. Here is the link from SAC with continuous action space: https://spinningup.openai.com/en/latest/algorithms/sac.html I do not know what I'm doing wrong. The problem is the network do not learn anything on the cartpole environment. The full code on github: https://github.com/tk2232/sac_discrete/blob/master/sac_discrete.py Here is my idea how to calculate the loss for

TensorFlow: How to combine rows of tensor with summing the 2nd element of tensor which has the same 1st element?

落爺英雄遲暮 提交于 2021-02-08 10:21:14
问题 For example, I want to add the 2nd element of this tensor where the 1st element is same. Any Numpy based solution is also welcomed! From : x = tf.constant([ [1., 0.9], [2., 0.7], [1., 0.7], [3., 0.4], [4., 0.8] ], dtype=tf.float32) To: x = tf.constant([ [1., 1.6], [2., 0.7], [3., 0.4], [4., 0.8] ], dtype=tf.float32) 回答1: numpy solution: x = np.array([ [1., 0.9], [2., 0.7], [1., 0.7], [3., 0.4], [4., 0.8]]) ans = np.array([[i,np.sum(x[np.where(x[:,0]==i), 1])] for i in set(x[:,0])]) gives

TensorFlow: How to combine rows of tensor with summing the 2nd element of tensor which has the same 1st element?

喜你入骨 提交于 2021-02-08 10:19:43
问题 For example, I want to add the 2nd element of this tensor where the 1st element is same. Any Numpy based solution is also welcomed! From : x = tf.constant([ [1., 0.9], [2., 0.7], [1., 0.7], [3., 0.4], [4., 0.8] ], dtype=tf.float32) To: x = tf.constant([ [1., 1.6], [2., 0.7], [3., 0.4], [4., 0.8] ], dtype=tf.float32) 回答1: numpy solution: x = np.array([ [1., 0.9], [2., 0.7], [1., 0.7], [3., 0.4], [4., 0.8]]) ans = np.array([[i,np.sum(x[np.where(x[:,0]==i), 1])] for i in set(x[:,0])]) gives

Installing Tensorflow 1.9 in Windows

眉间皱痕 提交于 2021-02-08 08:53:19
问题 I am trying to install tensorflow in Windows, pip3 install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.9.0-py3-none-any.whl The error I got is Collecting protobuf>=3.4.0 (from tensorflow==1.9.0) Could not find a version that satisfies the requirement protobuf>=3.4.0 (from tensorflow==1.9.0) (from versions: ) No matching distribution found for protobuf>=3.4.0 (from tensorflow==1.9.0) I googled online and I couldn't find any solutions. I am using python 3.5 64 bit

Optimizing Tensorflow for many small matrix-vector multiplications

本小妞迷上赌 提交于 2021-02-08 08:52:09
问题 To build up a capsule network training script, I need to compute many small matrix-vector multiplications. The size of each weight matrix is at most 20 by 20. The number of weight matrices is more more than 900. I'm curious tf.matmul or tf.linalg.matvec is the best option for this. Could anybody give me a hint to optimize the training script? 回答1: EDIT: Looking at the notebook that you are referring to, it seems you have the following parameters: batch_size = 50 caps1_n_caps = 1152 caps1_n

从零开始学Pytorch(零)之安装Pytorch

时光毁灭记忆、已成空白 提交于 2021-02-08 08:47:09
点击上方“ 计算机视觉cv ”即可“进入公众号” 重磅干货第一时间送达 Pytorch优势   聊聊为什么使用Pytorch,个人觉得Pytorch比Tensorflow对新手更为友善,而且现在Pytorch在学术界使用的得更多,大有逆袭Tensorflow之势。最近两年的顶会文章中,代码用Pytorch的比Tensorflow多。大家如果对Tensorflow也感兴趣,完全可以学习了Pytorch之后继续学习Tensorflow,基本原理都是相通的。让我们开始开启愉快的Pytorch学习之旅吧! 在Ubuntu系统或是windows系统安装Pytorch   首先打开Pytorch的官网:https://pytorch.org/。在首页我们可以看到有各种配置可选,我们这里选择CPU或是GPU的版本都可以。一般选择GPU版本的Pytorch,这样运行大型的程序速度会快很多。而要运行GPU的Pytorch,就需要在电脑(不管是Ubuntu系统还是windows系统)安装相应的CUDA9和cudnn7,这两个安装起来有时候会遇到一大堆问题,所以需要一步一步解决。推荐一个我写的在Ubuntu系统安装教程的博客,按照博客上写的一步步来就可以啦。 博客链接:https://blog.csdn.net/xiewenrui1996/article/details/102736238 。  

Are Keras custom layer parameters non-trainable by default?

喜夏-厌秋 提交于 2021-02-08 08:42:11
问题 I built a simple custom layer in Keras and was surprised to find that the parameters were not set to trainable by default. I can get it to work by explicitly setting the trainable attribute. I can't explain why this is by looking at documentation or code. Is this how it is supposed to be or I am doing something wrong which is making the parameters non-trainable by default? Code: import tensorflow as tf class MyDense(tf.keras.layers.Layer): def __init__(self, **kwargs): super(MyDense, self)._