tensorflow2.0

Keras ValueError: Dimensions must be equal, but are 9 and 400 for '{{node Equal}}' with input shapes: [?,9], [?,300,400]

我们两清 提交于 2021-01-28 06:11:48
问题 I'm trying to train a very simple Keras network to classify some one-hot encoded images saved as np.array . The input data structure is made of a .npy file, with 500 images (3 arrays each one, as it's RGB) and a one-hot encoded array with each image to determine it's classification. Each image is 400x300 pixels (Width x Height), and the target output should be of 9 classes. Hence, each image has a shape of (300, 400, 3) and each one-hot encoded label list has a length of 9 . This is the code

Tensorflow 2 ValueError: Shapes (20, 1) and (20, 2) are incompatible in gym environment

心不动则不痛 提交于 2021-01-28 05:34:43
问题 Just for learning I wanted to test this code. But there is a problem in it. I do not understand the problem. It says: ValueError: Shapes (20, 1) and (20, 2) are incompatible from the line loss = network.train_on_batch(states, discounted_rewards) Maybe there is something new in Tensorflow that was not there, the it was implemented. The code from the website: https://adventuresinmachinelearning.com/policy-gradient-tensorflow-2/ import gym import tensorflow as tf from tensorflow import keras

Tensorflow 2.3: AttributeError: 'Tensor' object has no attribute 'numpy'

醉酒当歌 提交于 2021-01-27 19:09:40
问题 I wanted to load the text file borrowed from here, where each line represent a json string like following: {"overall": 2.0, "verified": true, "reviewTime": "02 4, 2014", "reviewerID": "A1M117A53LEI8", "asin": "7508492919", "reviewerName": "Sharon Williams", "reviewText": "DON'T CARE FOR IT. GAVE IT AS A GIFT AND THEY WERE OKAY WITH IT. JUST NOT WHAT I EXPECTED.", "summary": "CASE", "unixReviewTime": 1391472000} I would like to extract only reviewText and overall feature from the dataset using

keras ImageDataGenerator interpolates binary mask

你离开我真会死。 提交于 2021-01-27 06:34:13
问题 I am training a neural network to predict a binary mask on mouse brain images. For this I am augmenting my data with the ImageDataGenerator from keras. But I have realized that the Data Generator is interpolating the data when applying spatial transformations. This is fine for the image, but I certainly do not want my mask to contain non-binary values. Is there any way to choose something like a nearest neighbor interpolation when applying the transformations? I have found no such option in

Why it's necessary to frozen all inner state of a Batch Normalization layer when fine-tuning

时间秒杀一切 提交于 2021-01-24 09:38:51
问题 The following content comes from Keras tutorial This behavior has been introduced in TensorFlow 2.0, in order to enable layer.trainable = False to produce the most commonly expected behavior in the convnet fine-tuning use case. Why we should freeze the layer when fine-tuning a convolutional neural network? Is it because some mechanisms in tensorflow keras or because of the algorithm of batch normalization? I run an experiment myself and I found that if trainable is not set to false the model

Tensorflow 2.0: custom keras metric caused tf.function retracing warning

假如想象 提交于 2021-01-20 07:14:22
问题 When I use the following custom metric (keras-style): from sklearn.metrics import classification_report, f1_score from tensorflow.keras.callbacks import Callback class Metrics(Callback): def __init__(self, dev_data, classifier, dataloader): self.best_f1_score = 0.0 self.dev_data = dev_data self.classifier = classifier self.predictor = Predictor(classifier, dataloader) self.dataloader = dataloader def on_epoch_end(self, epoch, logs=None): print("start to evaluate....") _, preds = self

tensorflow installation in python 3.9.0(64 bit) and pip version 20.2.3 .?

心已入冬 提交于 2021-01-07 02:53:37
问题 I want to install TensorFlow, I have tried everything from reinstalling everything to trying different versions it doesn't help. I have tried it with python 3.9.0 and pip version 20.0.3 回答1: The Official TensorFlow website specifies python 3.5-3.8. You need to create a new environment as suggested in the previous answer with a new version of python, or uninstall python 3.9 and install other version. I use python 3.6.8 for Tensorflow and it works great. 回答2: I use Anaconda and I have 2

conditional assignment of tf.variable in Tensorflow 2

丶灬走出姿态 提交于 2021-01-05 07:22:53
问题 For numpy we have threshold = 3 a = np.array([1,2,3,4,5,6]) a[a>=3] = 199 # a is [1, 2, 199, 199, 199, 199] How to write a similar code in tensorflow 2 b = tf.Variable(a) Thanks. 回答1: Sure, you can use tf.where to conditionally set values: b = tf.Variable(a) tf.where(b >= 3, 199, b) # <tf.Tensor: shape=(6,), dtype=int64, numpy=array([ 1, 2, 199, 199, 199, 199])> 来源: https://stackoverflow.com/questions/65449671/conditional-assignment-of-tf-variable-in-tensorflow-2

What types of operations will/will not plugin the computational graph in the Tensorflow 2?

有些话、适合烂在心里 提交于 2021-01-05 07:21:33
问题 Based on this post, we can change the tf.variable threshold = 3 a = np.array([1,2,3,4,5,6]) b = tf.Variable(a) b = tf.where(b >= threshold, 199, b) Will b=tf.where(b>=3, 199, b) be plugin to the computational graph and affect the gradient of b in the back propragration? Or more general questions: What types of operations will/will not plugin the computational graph in the Tensorflow 2 ? 来源: https://stackoverflow.com/questions/65449945/what-types-of-operations-will-will-not-plugin-the

conditional assignment of tf.variable in Tensorflow 2

ぃ、小莉子 提交于 2021-01-05 07:21:24
问题 For numpy we have threshold = 3 a = np.array([1,2,3,4,5,6]) a[a>=3] = 199 # a is [1, 2, 199, 199, 199, 199] How to write a similar code in tensorflow 2 b = tf.Variable(a) Thanks. 回答1: Sure, you can use tf.where to conditionally set values: b = tf.Variable(a) tf.where(b >= 3, 199, b) # <tf.Tensor: shape=(6,), dtype=int64, numpy=array([ 1, 2, 199, 199, 199, 199])> 来源: https://stackoverflow.com/questions/65449671/conditional-assignment-of-tf-variable-in-tensorflow-2