New answers tagged

0

For string data, use get_dummies() (from Pandas). to_categorical() takes integers as inputs. There are two important differences between Keras: to_categorical() and Pandas: get_dummies(). Keras: to_categorical() to_categorical() takes integers as input (no strings allowed). to_categorical() generates dummies starting at 0 by default! Looking at the ...


0

You are correct to approach this as a regression problem, mostly because you are interested in the order of your outputs. For example if there are 1000 people present and you predict 1005, it's a better prediction than 7005. If you were treating this as a classification problem, both of these would be interpreted as missclassifications. The most practical ...


0

Find a working Keras setup for a pretrained model with custom data generator here. Note that validation data should not be augmented! from keras.preprocessing.image import ImageDataGenerator train_datagen = ImageDataGenerator( rescale=1./255, rotation_range=40, width_shift_range=0.2, height_shift_range=0.2, shear_range=0.2, ...


0

One of the major issue is the amount of records per categories. Definitely using data augmentation is always helpful to get good accuracy but much better approach is to use transfer learning techniques with data augmentation. In your approach model is started overfitting because of that it's started having good training accuracy but bad validation accuracy. ...


0

I am assuming from the description inside main directory there are more directories of Apples, Bananas, Oranges, etc. and inside them you have .txt files containing information about the images. import shutil with open(file_path, 'r') as f: img_names = f.readlines() img_names = [img.strip() for img in img_names] for i in range(len(img_names)): ...


1

There are some papers which tell us that lower batch size may generalize better than large batch size. and large batch size may cause regularization in the model too. maybe that is the reason Bayesian optimization is suggesting a lower batch size for your dataset. Please check below papers, https://openreview.net/pdf?id=B1eyO1BFPr https://openreview.net/...


1

Please refer to the source code provided at https://gist.github.com/swghosh/f728fbba5a26af93a5f58a6db979e33e which should assist you in writing custom generators (basis ImageDataGenerator) for training end to end multi-output models. In the provided example, GoogLeNet is being trained which consists of two auxiliary classifiers and thus, comprising 3 outputs ...


0

This actually makes sense since the magnitude of the data is much smaller when you fit Log(y) = model(X). $log error = \frac{1}{n} \sum_{t=1}^{n} abs( \frac{log(y_{t})-model(X_{t})}{log(y_{t})})$ $error = \frac{1}{n} \sum_{t=1}^{n} abs(\frac{y_{t}- exp(model(X_{t}))}{y_{t}})$ also, MAPE, is Mean Absolute Percentage Error.


-1

You are not supposed to apply weights to your validation set since it is supposed to measure your model's performance. If you'll do that you'll probably get better results for validation but once your model is deployed it will perform worse on new data. Weighting, resampling techniques etc. - they all should be done on the training set only!


0

To complement the other two answers, you can use various model-agnostic methods to assess feature importance. See this nice e-book: Interpretable Machine Learning - A Guide for Making Black Box Models Explainable by Christoph Molna


1

Well, there are several ways you can do that. A quite powerful solution is to define a pred layer class PredLayer(Layer): """ Layer object to calculate distance between query_embeddings and supposrt embeddings. """ def __init__(self, **kwargs): super(PredLayer, self).__init__(**kwargs) def euclidean_distance(self, inputs): ...


0

This is sklearn bug. You should reduce the version of sklearn: conda install scikit-learn==0.21.2


1

Maybe the distribution of the validation data is not similar to the training data, and therefore the training signal does not lead the model to perform well on the validation data. The key point here is therefore: how did you split the data into training and validation?


1

I think the two following links could help you 1, 2. The first one is a tutorial, which introduces you how to display images in TensorBoard. If you look at the part on the confusion matrix, you should find a way to make your desired callback, i.e. a callback which involves displaying an image. The second link is also a tutorial that shows you how to ...


1

What you want to do is multi-class classification, but loss and your network is made for binary classification. Change: train_generator=train_datagen.flow_from_directory( train_data_dir, target_size=(img_width,img_height), batch_size=batch_size, class_mode='binary') validation_generator = test_datagen.flow_from_directory( ...


0

Maybe clean your dataset? Fastai has some nice tools for that - you basically remove from your data the images which are most confidently classified incorrectly. I can expand with some code example later. Edit: The function I'm talking about is ds, idxs = DatasetFormatter().from_toplosses(learn) It opens an interctive tool for relabeling/deleting images ...


0

use flow_from_dataframe import pandas as pd data = pd.read_csv("filename.csv") df["category"] = df["category"].replace({0: 'cat', 1: 'dog'}) train_df, validate_df = train_test_split(df, test_size=0.20, random_state=42) train_df = train_df.reset_index(drop=True) validate_df = validate_df.reset_index(drop=True) train_datagen = ImageDataGenerator( ...


0

You're just overfitting here. That's a fairly complex network for the simple MNIST data set. It's fairly easy to separate the MNIST classes, so even though your overfit network is starting to do worse on the validation set - it's getting less certain about the correct answers, believing the wrong ones more - the most-probable class is still almost always ...


0

Usually this is due to a learning rate that is too high, it passes over the Loss function minimum and starts overshooting. Of course I can't be sure that's the reason but this is my best guess. Try to simplify your optimizer, use Adam() optimizer alone (without moving average) and set a fairly small learning rate, something like 0.001 or even 0.0001. Let's ...


2

Unfortunately, there is no direct way to assess the "importance" of a variable in a Neural Network. One option, very time consuming, consists in removing each variable, one by one, replacing it with random noise, and checking how the performance changes. That will give you an idea on the contribution of a variable. Alternatively, stick with importance ...


2

For feature importance, you might want to consider using Shapley values or LIME. There are some examples here.


0

As explained here you can define your custom metric. You only need to use validation set weight for calculating the score. def my_metric(y_true, y_pred): sw=compute_sample_weight('balanced',y_true) return accuracy_score(y_true, y_pred, sample_weight=sw)


1

You can find more details about the arguments of Dense Layer in Keras Sequential model here. Example # as first layer in a sequential model: model = Sequential() model.add(Dense(32, input_shape=(16,))) # now the model will take as input arrays of shape (*, 16) # and output arrays of shape (*, 32) # after the first layer, you don't need to specify # the ...


0

512 is the number of neurons in the dense layer. Each neuron is connected to the input layer (which have the input_shape)


0

As per the documentation, first argument is the "Units" ,output size.


0

I solved the problem, I added an additional conv layer with 64 feature maps and increased size of dense layer from 512 to 1024 also I trained the model with the increased number of epochs(from 50 to 150). The result is impressive! Everything as I wanted.


1

From your description, it seems that you are not shuffling your training data. You should shuffle your data, and do it differently at every epoch. Once the data is shuffled, you should not see the behavior you describe.


1

Have you already plotted the training and validation loss over multiple epochs? What you would expect is something that looks like an exponential decay. Chances are your models learns the mean of the target variable in the first few batches, which reduces the MSE-loss already considerably and only later learns the subtle differences in your data. You can ...


1

You could use class KerasClassifier from keras.wrappers.scikit_learn, which wraps a Keras model in a scikit-learn interface, so that it can be used like other scikit-learn models and then you could evaluate it with scikit-learn's scoring functions, e.g.: from keras.wrappers.scikit_learn import KerasClassifier from sklearn.metrics import roc_curve, auc ...


0

In tensorflow-tutorials-for-text they are implementing bahdanau attention layer to generate context vector by giving encoder inputs, decoder hidden states and decoder inputs. Encoder class is simply passing the encoder inputs from Embedding layer to GRU layer along with encoder_states and returns encoder_outputs and ecoder_states. If we use LSTM instead ...


2

Sounds like you're just looking for EarlyStopping, which will stop training when validation loss does not improve for N epochs. It's the same as Iter in catboost.


0

Notice that the next hidden state $h_t$ is produced by applying pointwise scalar operations to the next cell state $C_t$. (The precise formula $h_t = o_t * \tanh(C_t)$ can be found in the blog post you link to.) Therefore, the cell state and the hidden state have the same dimensionality.


0

In heat maps, generally reddish regions represents higher values where as bluish ones represent lower.


0

It doesn't seem that it is about the size of the model. I am no SageMaker expert, but the error message suggests that the model was deployed, but that something went wrong when the health check was run. This could be caused by many different things, but the most probable would be that there is a bug in the code. Please check the following: Can the model be ...


0

Here you can find the code to train an LSTM via keras and tune it via keras tuner, bayesian option: #2 epoch con 20 max_trials from kerastuner import BayesianOptimization def build_model(hp): model = keras.Sequential() model.add(keras.layers.LSTM(units=hp.Int('units',min_value=8, max_value=64, ...


1

With Softmax as activation in final layer, you should have n neurons, where n is the number of classes. Here is an explanation: https://developers.google.com/machine-learning/crash-course/multi-class-neural-networks/softmax So basically: model.add(Dense(n_classes, activation='softmax')) If you are using one hot encoding: model.add(Dense(y_train[1], ...


1

I cannot say for sure, but it seems that it might be an error in the printout. The validation loss doesn't seem to spike, so it seems that the loss may not actually be what is printed. I can only advise to run training multiple times and see if this happens again. If yes, try toying with the learning rate. There is a small chance that the learning rate ...


0

This is the closer answer I can find. # Input inputs = Input(shape=(max_length,), name="Input") # Embedding embed = Embedding(input_dim=n_words+1, output_dim=embedding_size, input_length=max_length, name="Embedding")(inputs) # Bi-LSTM encoder = Bidirectional(LSTM(units=hidden_state_encoder_size, ...


0

Try this, and tune alpha. model = tf.keras.models.Sequential([ keras.layers.Flatten(input_shape=(28,28)), keras.layers.Dense(128,activation=tf.keras.layers.LeakyReLU(alpha=0.3)), keras.layers.Dense(10,activation=tf.nn.softmax) ])


0

In addition to the answer by @TitoOrt I like to point out that it can be useful to make predictions in Keras - when trained using a data generator - also using a generator function. I had some trouble when I worked out a solution in the first place, so I documented the general logic on Stackoverflow. The code also includes proper preprocessing of test images....


1

You are applying a preprocessing step to both your train and test images: rescale=1./255. This normalises the values of the image pixels to be in the range of (0,1) instead of (0,255). However, when you are doing your predictions you are not applying this rescaling to your test image. This translates into testing an image with pixel values 255 higher than ...


0

Does this work for you? After the Bi-Directional LSTM layer, I sum the tensor over the batch axis and then divide by the batch size. from tensorflow.keras import layers, Sequential from tensorflow.keras.models import Model from tensorflow.keras import backend as K from tensorflow.keras.utils import plot_model inputs = layers.Input(batch_shape=(4, 500), ...


0

The model doesn't know which X values would yield the "best" result. You could run the model a couple of times (tf.predict()) with dummy data, record the results (inputs and predictions), build a Genetic ML model that optimizes X combinations for high (if that's what you consider "good") Y values.


1

Call model_name.summary() This will return you the correct value for the total number of parameters.


0

First of all, to reassure you, SMOTE should work on text data. SMOTE will work on any data type as long as there is a way to compute the distance between data points. Based on the error message you receive, it seems that it's an implementation issue (adding part of your code or how much data you have would greatly help). As the error states, you have only ...


2

from keras.applications.resnet50 import ResNet50 resnet_model = ResNet50(weights='imagenet') #resnet_model.count_params() resnet_model.summary() Total params: 25,636,712 Trainable params: 25,583,592 Non-trainable params: 53,120 Check your code once to be sure that it is ResNet50


1

Sequential API is simpler to write and to read. Functional API on the other hand gives you more freedom in the implementation of the ANN architecture. More specifically, Functional API is what you need when the layers of your Networks do not form a simple concatenation or sequence (i.e. the first sends a signal to the second, that sends a signal to the third,...


0

Alright, so... I got help from someone. He mentions changing LSTM to return_sequences. # Input inputs = Input(shape=(max_length,), name="Input") # Embedding embed = Embedding(input_dim=n_words+1, output_dim=embedding_size, input_length=max_length, name="Embedding")(inputs) # Bi-LSTM encoder = ...


0

To get around this issue, I would suggest doing training in batches. This solves the issue of not being able to load 100,000 images and also removes the need to figure out how to merge the models.


0

Overfitting is a result of the entire model. It is best to visualize every part of the model to understand how the combination of elements is overfitting. Ideally, you should visualize all elements on the same interactive figure so how the combination is overfitting. If that is not possible or the interpretation is difficult, then many single element ...


Top 50 recent answers are included