tensorflow2.0

Accessing layer's input/output using Tensorflow 2.0 Model Sub-classing

天大地大妈咪最大 提交于 2020-04-13 17:02:25
问题 Working on a university exercise, I used the model sub-classing API of TF2.0. Here's my code (it's the Alexnet architecture, if you wonder...): class MyModel(Model): def __init__(self): super(MyModel, self).__init__() # OPS self.relu = Activation('relu', name='ReLU') self.maxpool = MaxPooling2D(pool_size=(3, 3), strides=(2, 2), padding='valid', name='MaxPool') self.softmax = Activation('softmax', name='Softmax') # Conv layers self.conv1 = Conv2D(filters=96, input_shape=(224, 224, 3), kernel

Tensorflow 2.0 can't use GPU, something wrong in cuDNN? :Failed to get convolution algorithm. This is probably because cuDNN failed to initialize

…衆ロ難τιáo~ 提交于 2020-04-10 06:02:50
问题 I am trying to understand and debug my code. I try to predict with a CNN model developed under tf2.0/tf.keras on GPU, but get those error messages. could someone help me to fix it? here is my environmental configuration enviroments: python 3.6.8 tensorflow-gpu 2.0.0-rc0 nvidia 418.x CUDA 10.0 cuDNN 7.6+** and the log file, 2019-09-28 13:10:59.833892: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10.0 2019-09-28 13:11:00.228025

Tensorflow 2.0 can't use GPU, something wrong in cuDNN? :Failed to get convolution algorithm. This is probably because cuDNN failed to initialize

浪尽此生 提交于 2020-04-10 06:01:11
问题 I am trying to understand and debug my code. I try to predict with a CNN model developed under tf2.0/tf.keras on GPU, but get those error messages. could someone help me to fix it? here is my environmental configuration enviroments: python 3.6.8 tensorflow-gpu 2.0.0-rc0 nvidia 418.x CUDA 10.0 cuDNN 7.6+** and the log file, 2019-09-28 13:10:59.833892: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10.0 2019-09-28 13:11:00.228025

Tensorflow 2.0 Custom loss function with multiple inputs

僤鯓⒐⒋嵵緔 提交于 2020-04-10 05:32:05
问题 I am trying to optimize a model with the following two loss functions def loss_1(pred, weights, logits): weighted_sparse_ce = kls.SparseCategoricalCrossentropy(from_logits=True) policy_loss = weighted_sparse_ce(pred, logits, sample_weight=advantages) and def loss_2(y_pred, y): return kls.mean_squared_error(y_pred, y) however, because TensorFlow 2 expects loss function to be of the form def fn(y_pred, y_true): ... I am using a work-around for loss_1 where I pack pred and weights into a single

Freezing graph to pb in Tensorflow2

那年仲夏 提交于 2020-04-10 03:30:07
问题 We deploy lot of our models from TF1 by saving them through graph freezing: tf.train.write_graph(self.session.graph_def, some_path) # get graph definitions with weights output_graph_def = tf.graph_util.convert_variables_to_constants( self.session, # The session is used to retrieve the weights self.session.graph.as_graph_def(), # The graph_def is used to retrieve the nodes output_nodes, # The output node names are used to select the usefull nodes ) # optimize graph if optimize: output_graph

Anyway to work with Keras in Mac with AMD GPU?

早过忘川 提交于 2020-04-01 16:58:11
问题 I have a MacBook Pro with AMD processor and I want to run Keras (Tensorflow backend) in this GPU. I came to know Keras only works with NVIDIA GPUs. What is the workaround (if possible)? 回答1: You can OpenCL library to overcome this. I have tested it and it is working fine for me. Note: I have python version 3.7 and I will be using pip3 for package installation. Steps: Install OpenCL package with the following command pip3 install pyopencl Install PlaidML library using following command pip3

Anyway to work with Keras in Mac with AMD GPU?

大憨熊 提交于 2020-04-01 16:55:15
问题 I have a MacBook Pro with AMD processor and I want to run Keras (Tensorflow backend) in this GPU. I came to know Keras only works with NVIDIA GPUs. What is the workaround (if possible)? 回答1: You can OpenCL library to overcome this. I have tested it and it is working fine for me. Note: I have python version 3.7 and I will be using pip3 for package installation. Steps: Install OpenCL package with the following command pip3 install pyopencl Install PlaidML library using following command pip3

Equality comparison does not work inside TensorFlow 2.0 tf.function()

我的未来我决定 提交于 2020-03-26 03:53:13
问题 Following the discussion on TensorFlow 2.0 AutoGraphs, I've been playing around and noticed that inequality comparisons such as > and < are specified directly, whereas equality comparisons are represented using tf.equal . Here's an example to demonstrate. This function uses > operator and works well when called: @tf.function def greater_than_zero(value): return value > 0 greater_than_zero(tf.constant(1)) # <tf.Tensor: id=1377, shape=(), dtype=bool, numpy=True> greater_than_zero(tf.constant(-1

Equality comparison does not work inside TensorFlow 2.0 tf.function()

人走茶凉 提交于 2020-03-26 03:53:09
问题 Following the discussion on TensorFlow 2.0 AutoGraphs, I've been playing around and noticed that inequality comparisons such as > and < are specified directly, whereas equality comparisons are represented using tf.equal . Here's an example to demonstrate. This function uses > operator and works well when called: @tf.function def greater_than_zero(value): return value > 0 greater_than_zero(tf.constant(1)) # <tf.Tensor: id=1377, shape=(), dtype=bool, numpy=True> greater_than_zero(tf.constant(-1

How to print value of tensorflow.python.framework.ops.Tensor in Tensorflow 2.0?

℡╲_俬逩灬. 提交于 2020-03-24 00:13:30
问题 I have a few tensors in my code and and need to get the values of those tensors. This is one them. How to print the values of tensor OA? Input:OA Output: <tf.Tensor 'Sum_1:0' shape=(1, 600) dtype=float32> Input:type(OA) Output: tensorflow.python.framework.ops.Tensor I have tried all the available functions like tf.print(), eval(), tensor.numpy(). None of them worked for me in Tensorflow 2.0. It seems they work only for 'EagerTensor' and not for 'ops.Tensor'. 1) OA.eval(session=sess) Error: