New answers tagged

1

As has been mentioned, pip install and the appropriate TensorFlow version should do it for you. However, if you are having trouble installing locally (maybe your Python version is not suited for TensorFlow v2.0), there is always the option of spinning up a Jupyter Notebook in Amazon SageMaker and running the notebook through the cloud. For instance, using ...


1

You install the version you want with: pip install tensorflow=={version you want} for example: pip install tensorflow==2.1.0-rc1 If you are working in Google Colab it's even simpler, just type: %tensorflow_version 2.x import tensorflow as tf and it will automatically import the latest version of TensorFlow 2. Eager mode is default in TensorFlow 2.x, ...


0

If you really just want to guess the sign, you should just build a new target : 0 if the sign is negative 1 if the sign is positive... That would fit with your binary classification approach and the metrics you want to use.


0

If you label your data using -1 and 1 as classes, then yes you can. However, there are two reasons why data scientists normally prefer Sigmoid activations: Loss functions, such as cross entropy based, are designed for data in the [0, 1] interval. Better interpretability: data in [0, 1] can be thought as probabilities of belonging to acertain class, or as a ...


0

I created a rule to achieve reproducibility: Works for python 3.6, not 3.7 First install Keras 2.2.4 After install tensorflow 1.9 And finally in the code: import numpy as np import random as rn import tensorflow as tf import keras from keras import backend as K #-----------------------------Keras reproducible------------------# SEED = 1234 tf....


0

This tutorial explains in a nice and simple way how to create a data generator which you can pass to your Keras model to train using fit_generator(). Two things to keep in mind about Keras generators, in order to be compatible with Tensorflow 2.x requirements: Your generator should inherit from keras.utils.Sequence, which allows for internal parallelization ...


0

First you need to define a function using backend functions. As an example, here is how I implemented the swish activation function: from keras import backend as K def swish(x, beta=1.0): return x * K.sigmoid(beta * x) This allows you to add the activation function to your model like this: model.add(Conv2D(64, (3, 3))) model.add(Activation(swish)) ...


4

Sure, here is a skeleton in TF 2.0. import tensorflow as tf weights = tf.Variable(tf.random.normal(shape=(784, 10), dtype=tf.float64)) biases = tf.Variable(tf.random.normal(shape=(10,), dtype=tf.float64)) def logistic_regression(x): lr = tf.add(tf.matmul(x, weights), biases) return lr def cross_entropy(y_true, y_pred): y_true = tf.one_hot(...


1

I have not used PELU activation function by myself, so dont know much about its performance benefits but can say a, b, and c looks to be hyperparameters only. and it can be directly implemented in tensorflow 2.0 as tf.cond(h, lambda:c*h, lambda:a(tf.exp(h/b)-1))


5

I need a way to supress previous answers. The answer to the question depends on the particular network that you are using. What kind of generative model is it? GAN? Autoencoder? Seq2Seq RNN? Having said that, if your network keeps outputting the same result, this is usually referred to as "mode collapse", which is typical for GANs. If your network is a GAN,...


0

You need mini batch gradient descent. At each training iteration, you feed a batch of data into the model. This is also a great technique to prevent overfitting and making your gradient get stuck into local minima. Size of the batch is another hyperparameter. Usually batch sizes vary in the 50-250 range, but that's completely up to you. Smaller batches are ...


1

You can use generator to read the data if your model uses "Mini-Batch SGD"-like optimization method which just uses a small batch of samples each step. For example, df_iterator = pandas.read_csv(your_data,chunksize=batch_size,iterator=True) for small_batch in df_iterator: #feed it to your model's input


2

This flag is used to have truncated back-propagation through time: the gradient is propagated through the hidden states of the LSTM across the time dimension in the batch and then, in the next batch, the last hidden states are used as input states for the LSTM. This allows the LSTM to use longer context at training time while constraining the number of ...


1

In short, value of model.predict() function is interpreted as mentioned in option 2. In order to clarify, let's assume we are talking about spam detection application. Label 0 represents that text/email is not spam and label 1 represents that text/email is spam. Suppose, after running the function model.predict(), we get value 0.9899. Then we can interpret ...


0

please check this answer and see if it helps . Somehow I feel that you are getting the predict probability rather than the prediction itself https://stackoverflow.com/questions/40002084/how-to-output-a-prediction-in-tensorflow


0

I somehow feel that the issue rather than being technical is more functional in nature. One should try converting age into bins of age ranges and then use it as a multiclass classification problem statement. Predicting age from a picture is something that even humans fails at so that inherent misintepretation would be "learned" by NN as well and MAE always ...


0

First, what you need to consider is not whether you can or not, but whether your practice so far or what you are planning to do make sense for your use-cases. Basically choose whichever make more sense for your use-cases. After you decide, now for your question, It is very possible. The next thing you want to consider is what loss function to use. Note that ...


1

When implementing a model from a paper to reproduce their results, it is very important to pay attention to all the details. For this case there are some important differences when comparing to the CIFAR10 results of ResNet: You are using the Adam optimizer, while the ResNet paper uses SGD with a learning rate schedule. Adam is known to have issues ...


0

I just figured out the same issue. Try to pass a dictionary like: { 0: 1.0, 1: 10, 2: 20, 3: 20, 4: 20 } to class_weight in model.fit() and it will solve the problem. Understood that it says a list will also work in the docs - but seems like it does not work as well for me.


0

Imagine you have a basic maths framework, a lot of functions doing addition, subtraction, multiplication and division. Imagine in everyday life you often need to compute averages. Then you make a function (using the functions from the framework, inside it), that will take an array of numbers as parameters an return the mean. The framework is actually ...


3

Lets go back to basics here. It is not possible to only use Keras without using a backend, such as Tensorflow, because Keras is only an extension for making it easier to read and write machine learning programs. All the actual calculations needed to create models are not implemented in Keras, which is why you need to use a backend library for anything to ...


1

Keras used to use 2 backends(Theano and Tensorflow), but now only supports Tensorflow because of the discontinuation of Theano. The reason why Keras uses Tensorflow as it's backend is because it is an abstraction layer. It is the easiest way to get started with AI and machine learning because all of the core algorithms are implemented in tensorflow and ...


34

This makes more sense when understood in its historical context. These were the chronological events: April 2009 Theano 0.1 is released. It would dominate the deep learning framework scene for many many years. June 2015 Keras is created by François Chollet. The goal was to create an abstraction layer to make Theano easier to use, enabling fast prototyping. ...


1

The first point to note is that Keras can potentially use many backends (e.g. Theano before it was discontinued, Microsoft Cognitive Toolkit, to name a couple). It just so happens that Keras has proven to be the most popular among the community. As a result, TensorFlow has adapted to the extent that Keras is now the default API in TensorFlow 2.0. One of the ...


3

Additionally: Think of it as an abstraction layer. Keras gives nice and intuitive way to build and think about neural network, but you have to understand thats not how computer takes orders. Hiding this complexity behind Tensorflow allows us to think naturally about building a neural network and not all the details behind implementation. (On a general note ...


5

Keras is an application programming interface (API). It is a single interface that can support multi-backends, which means a programmer can write Keras code once and it can be executed in a variety of neural networks frameworks (e.g., TensorFlow, CNTK, or Theano). TensorFlow 2.0 is the suggested backend starting with Keras 2.3.0.


0

You may need to spend more time identifying the problem than looking for tricks that have worked in literature. So start with the simplest architecture and see how and on what values your network is converging. It's hard to know all the details but here are a few suggestions that might help. You may try different initializations and also random re-...


0

Try deeper network. Something like this. self.model = models.Sequential() self.model.add(layers.Dense(self.num_layers, activation="relu", input_shape=(self.x_train.shape[1],))) self.model.add(layers.Dense(self.num_layers//2, activation="relu")) self.model.add(layers.Dense(self.num_layers//4, activation="linear")) self.model.add(layers.Dense(1)) self.model....


0

TF Addons computes the F1 score and more generally the FBeta Score


0

You just need to ensure that the model you forecast with has a design matrix covering both the observed and forecasted timesteps. That is, you'd build a model including a component along the lines of sts.LinearRegression( design_matrix=tf.concat([temperature_for_observed_timesteps, temperature_for_forecast_timesteps], axis=-2), ...


1

I solved the problem following the advices in the comments of this discussion. I paste here my code: dizionario = dict({'1': 0, '10': 1, '11': 2, '12': 3, '13': 4, '14': 5, '15': 6, '16': 7, '17': 8, '18': 9, '19': 10, '2': 11, '20': 12, '21': 13, '22': 14, '23': 15, '24': 16, '25': 17, '26': 18, '27': 19, '28': 20, '29': 21, '3': 22, ...


1

I'll go through your questions one by one: Should i normalize my numerical data values before feeding to any type of autoencoder? if they are int and float values still i have to normalize? This is strongly suggested, for two reasons. First, if different variables are on different scales, weights distributions will be unequal. Larger scales will dominate ...


3

First question: How many layers? This is architectural question and one of them most important when constructing NN. Generally the more complex the task the more layers you should use to approximate (until a certain point than there is overkill, motivation for ResNet) If you are looking for some guidelines there are some good posts, but the research and ...


1

That code instantiates model over and over. model should be instantiated once and all other layers are added to that instance. Something like this: from tensorflow.keras.models import Sequential model = Sequential() model.add(Embedding(input_dim=n_words, output_dim=MAXLEN, input_length=MAXLEN)) model.add(Dropout(0.2)) model.add(Bidirectional(LSTM(units=...


2

I don't believe that's possible, in order for the model to return 0 or 1, your activation function on the output layer would have to return 0 or 1, which would mean that the activation function is non-differentiable, and you cannot do that. Also you can simplify your transformer function to: In [20]: predictions = np.array([[0.1], [0.9], [0.3], [0.6]]) ...


1

2 options. reinstall and try again (dont ask) option b) downgrade to versions 1.13.1 and lower (again dont ask) ofcourse you can ask I am just lazy


Top 50 recent answers are included