tensorflow

tf.keras.Model save: “AssertionError: Tried to export a function which references untracked object Tensor”

一曲冷凌霜 提交于 2021-01-29 08:12:32
问题 I'm running this Tensorflow NMT tutorial: https://github.com/tensorflow/addons/blob/master/docs/tutorials/networks_seq2seq_nmt.ipynb When I try to save the decoder: decoder.save('decoder') , I get: AssertionError: Tried to export a function which references untracked object Tensor("LuongAttention/memory_layer/Tensordot:0", shape=(1024, 23, 256), dtype=float32).TensorFlow objects (e.g. tf.Variable) captured by functions must be tracked by assigning them to an attribute of a tracked object or

Tensorflow 2.0 turn off tf.function retracing for prediction

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-29 08:11:21
问题 I am trying to generate prediction intervals for a simple RNN using dropout. I'm using the functional API with training=True to enable dropout during testing. To try different dropout levels, I defined a small function to edit the model configs: from keras.models import Model, Sequential def dropout_model(model, dropout): conf = model.get_config() for layer in conf['layers']: if layer["class_name"]=="Dropout": layer["config"]["rate"] = dropout elif "dropout" in layer["config"].keys(): layer[

I want to read data from TFRecord

余生颓废 提交于 2021-01-29 08:02:16
问题 I saved the image date into tfrecord, but I cannot parse it with tensorflow dataset api. My environment Ubuntu 18.04 Python 3.6.8 Jupyter Notebook Tensorflow 1.12.0 I saved the image data by following code, writer = tf.python_io.TFRecordWriter('training.tfrecord') # X_train: paths to the image, y_train: labels (0 or 1) for image_path, label in zip(X_train, y_train): image = cv2.imread(image_path) image = cv2.resize(image, (150, 150)) / 255.0 ex = tf.train.Example( features = tf.train.Features

Jupyter w/ Tensorflow pydotprint not found error

ⅰ亾dé卋堺 提交于 2021-01-29 07:52:16
问题 I'm using the tensorflow docker image run this way: docker run -it --rm -v $(realpath ~/Documents/notebooks):/tf/notebooks -p 8888:8888 tensorflow/tensorflow:latest-py3-jupyter I'm trying to generate dot files / plots of the model I've made, but all of the functions say: Failed to import pydot. You must install pydot and graphviz for pydotprint to work. At the top of my notebook, I have: !pip install pydot !pip install graphviz And I'm using Tensorflow 2.0.0 How do I get this to work?

TF model served using docker & C++ inference client on Windows 10

你说的曾经没有我的故事 提交于 2021-01-29 07:16:35
问题 I am trying code up a c++ tensorflow client to push images to the model which is served via tensorflow-serve docker, on Windows 10. docker run -p 8501:8501 --name tfserving_model_test --mount type=bind,source=D:/docker_test/model,target=/models/model -e MODEL_NAME=test_model -t tensorflow/serving Trying a simple code which was a part of TF serve (resnet_client.cc) example where I am passing a black image. // Preparing required variables to make a predict request. PredictRequest predictRequest

How to handle variable length data for LSTM

我怕爱的太早我们不能终老 提交于 2021-01-29 07:15:19
问题 From what I know the general steps to preprocess data for LSTM include the following steps vocab_size = 20000 # Only consider the top 20k words maxlen = 200 # Only consider the first 200 words of each movie review (x_train, y_train), (x_val, y_val) = keras.datasets.imdb.load_data(num_words=vocab_size) print(len(x_train), "Training sequences") print(len(x_val), "Validation sequences") x_train0 = keras.preprocessing.sequence.pad_sequences(x_train, maxlen=maxlen) x_val0 = keras.preprocessing

TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first

对着背影说爱祢 提交于 2021-01-29 07:14:40
问题 I am running a model on Google Colab.As I reproduce the code,I want to run one of the pieces of code to get the experimental results.And I get some error.Here is the code: cluster_args = { 'cluster_layers' : {1:400, 3:240}, 'conv_feature_size' : 1, 'reshape_exists' : False, 'features' : 'both', 'channel_reduction' : 'fro', 'use_bias' : False, 'linkage_method' : 'ward', 'distance_metric' : 'euclidean', 'cluster_criterion' : 'hierarchical_trunc', 'distance_threshold' : 1.60, 'merge_criterion' :

How can I convert a tensor into bounding box coordinates and labels in Javascript?

a 夏天 提交于 2021-01-29 07:13:47
问题 I've trained a .pb object detection model in python using Colab and converted it to the model.json format using the TensorFlow converter. I need to load this model inside the browser (no Node.js!) and run inference there. This is my complete code so far (images added in HTML using PHP): <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="../style.css"> </head>

Why am I getting an error “NotImplementedError: Cannot convert a symbolic Tensor to a numpy array” in Visual Studio?

拟墨画扇 提交于 2021-01-29 07:01:55
问题 My code is: import tensorflow as tf dec_inputs = tf.keras.Input(shape=(None,), name="dec_inputs") def create_look_ahead_mask(x): seq_len = tf.shape(x)[1] look_ahead_mask = 1 - tf.linalg.band_part(tf.ones((seq_len, seq_len)), -1, 0) return look_ahead_mask look_ahead_mask = tf.keras.layers.Lambda( create_look_ahead_mask, output_shape=(1, None, None), name='look_ahead_mask')(dec_inputs) It works in Colab. But generates an error when I try to run in Visual Studio. Why is that ? 来源: https:/

In tensorflow, is it possible to see another models build structure?

时光毁灭记忆、已成空白 提交于 2021-01-29 06:59:33
问题 For example, if I load somebody else's model, this is what I see: I want to get the code representation of this, for example: model = Sequential() model.add(Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=input_shape)) model.add(Conv2D(64, (3, 3), activation='relu')) ... etc Not saying that the above is correct, but I want to know if there a way for me to physically reconstruct the model in code, including all activation functions? I guess I can read the summary, but I don't