tensorflow

Problem converting tensorflow saved_model from float32 to float16 using TensorRT (TF-TRT)

孤街浪徒 提交于 2021-02-18 19:35:33
问题 I have a tensorflow (version 1.14) float32 SavedModel that I want to convert to float16. According to https://docs.nvidia.com/deeplearning/frameworks/tf-trt-user-guide/index.html#usage-example , I could pass "FP16" to precision_mode to convert the model to fp16. But the converted model, after checking the tensorboard, is still fp32: net paramters are DT_FLOAT instead of DT_HALF. And the size of the converted model is similar to the model before conversion. (Here I assume that, if converted

Converting pretrained saved model from NCHW to NHWC to make it compatible for Tensorflow Lite

本秂侑毒 提交于 2021-02-18 19:21:46
问题 I have converted a model from PyTorch to Keras and used the backend to extract the tensorflow graph. Since the data format for PyTorch was NCHW, the model extracted and saved is also that. While converting the model to TFLite, due to the format being NCHW, it cannot get converted. Is there a way to convert the whole graph into NHCW? 回答1: It is better to have a graph with the data-format matched to TFLite for faster inference. One approach is to manually insert transpose ops into the graph,

How to remove layers from a keras model in order to use as baseline for creating another model

五迷三道 提交于 2021-02-18 19:11:14
问题 I need to use a pre-trained model in Keras(keras.applications.VGG16) as a baseline for creating another model(for doing transfer learning) from the first layers of it. The end goal is to freeze and export the model for deployment on a raspberry pi with AIY vision kit. I've tried the common approach of: model_base = keras.applications.VGG16(input_tensor=inputs) x = model_base.get_layer(backbone_layer).output x = keras.layers.Flatten()(x) x = keras.layers.Dense(1)(x) model = keras.models.Model

ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found [duplicate]

那年仲夏 提交于 2021-02-18 19:07:50
问题 This question already has an answer here : can't import tensorflow in python, windows 10 64 bit (1 answer) Closed 7 months ago . I am trying to make a simple LSTM time-series model for predicting future prices using the past prices. I am getting error while running the code. I have imported keras in my code but I have not imported tensorflow directly. It shows the below error: Traceback (most recent call last): File "pricePredictor.py", line 29, in <module> from keras.models import Sequential

ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found [duplicate]

偶尔善良 提交于 2021-02-18 19:03:13
问题 This question already has an answer here : can't import tensorflow in python, windows 10 64 bit (1 answer) Closed 7 months ago . I am trying to make a simple LSTM time-series model for predicting future prices using the past prices. I am getting error while running the code. I have imported keras in my code but I have not imported tensorflow directly. It shows the below error: Traceback (most recent call last): File "pricePredictor.py", line 29, in <module> from keras.models import Sequential

How to save best model in Keras based on AUC metric?

走远了吗. 提交于 2021-02-18 18:00:33
问题 I would like to save the best model in Keras based on auc and I have this code: def MyMetric(yTrue, yPred): auc = tf.metrics.auc(yTrue, yPred) return auc best_model = [ModelCheckpoint(filepath='best_model.h5', monitor='MyMetric', save_best_only=True)] train_history = model.fit([train_x], [train_y], batch_size=batch_size, epochs=epochs, validation_split=0.05, callbacks=best_model, verbose = 2) SO my model runs nut I get this warning: RuntimeWarning: Can save best model only with MyMetric

How to save best model in Keras based on AUC metric?

走远了吗. 提交于 2021-02-18 17:59:28
问题 I would like to save the best model in Keras based on auc and I have this code: def MyMetric(yTrue, yPred): auc = tf.metrics.auc(yTrue, yPred) return auc best_model = [ModelCheckpoint(filepath='best_model.h5', monitor='MyMetric', save_best_only=True)] train_history = model.fit([train_x], [train_y], batch_size=batch_size, epochs=epochs, validation_split=0.05, callbacks=best_model, verbose = 2) SO my model runs nut I get this warning: RuntimeWarning: Can save best model only with MyMetric

Tensorflow running session multiple times in a loop

余生颓废 提交于 2021-02-18 17:50:32
问题 I'm trying out a simple Tensorflow code to compute the product of two matrices multiple times. My code is as follows: import numpy as np import tensorflow as tf times = 10 alpha = 2 beta = 3 graph = tf.Graph() with graph.as_default(): A = tf.placeholder(tf.float32) B = tf.placeholder(tf.float32) C = tf.placeholder(tf.float32) alpha = tf.constant(2.0, shape=[1, 1]) beta = tf.constant(3.0, shape=[1, 1]) D = alpha*tf.matmul(A, B) + beta*C with tf.Session(graph=graph) as session: tf.initialize

Tensorflow running session multiple times in a loop

那年仲夏 提交于 2021-02-18 17:50:26
问题 I'm trying out a simple Tensorflow code to compute the product of two matrices multiple times. My code is as follows: import numpy as np import tensorflow as tf times = 10 alpha = 2 beta = 3 graph = tf.Graph() with graph.as_default(): A = tf.placeholder(tf.float32) B = tf.placeholder(tf.float32) C = tf.placeholder(tf.float32) alpha = tf.constant(2.0, shape=[1, 1]) beta = tf.constant(3.0, shape=[1, 1]) D = alpha*tf.matmul(A, B) + beta*C with tf.Session(graph=graph) as session: tf.initialize

Avoiding tf.data.Dataset.from_tensor_slices with estimator api

我与影子孤独终老i 提交于 2021-02-18 12:35:10
问题 I'm am trying to figure out the recommended way to use the dataset api together with the estimator api. Everything I have seen online is some variation of this: def train_input_fn(): dataset = tf.data.Dataset.from_tensor_slices((features, labels)) return dataset which can then be passed to the estimator's train function: classifier.train( input_fn=train_input_fn, #... ) but the dataset guide warns that: the above code snippet will embed the features and labels arrays in your TensorFlow graph