New answers tagged

0

Number of batches = total number of samples in dataset/batch size. If the total samples are not completely divisible by batch size, then it will take the remaining in the next batch. Eg: 15x66+10=1000 which means it will take 66 batches of size 15 and for the final steps it takes only 10.


0

Try these: import everything from tensorflow keras API. tf.keras.models.load_model("./saved_models/our_model.h5", compile=False) (make sure you have model and weights both in the file)


0

Model.predict_classes gives you the most likely class only (highest probability value), therefore it is of dimension (samples,), for every input in sample there is one output - the class. To be more precise Model.predict_classes calls argmax on the output of predict. See the code (of predict_classes below) def predict_classes(self, X, batch_size=128, ...


1

A common way is to create a class inheriting tf.keras.utils.Sequence. This class implements a function __getitem__ which is called when you use model.fit() method. In this method, you can simply load one batch at a time, so no need to load the whole dataset. See the documentation. You can also directly use the .npz files when calling __getitem__. Shuffle ...


0

Hyperparameters are all the training variables set manually with a predetermined value before starting the training. You can think of Hyperparameters as configuration variables you set when running some software. We want to find the best configuration of hyperparameters which will give us the best score on the metric we care about on the validation / test ...


0

You have to create labels for each of the images and then split it into train and test. I believe you have 20,000 images - so you have to also have 1 label for each image not jus the 4 categories alone in an array. One of the most important steps in training a DNN model to do image classification (as is your case) or any image related task is creating labels ...


0

this can be done in multiple ways i am not one hundred percent understand the question because it is badly worded but there are 3 ways! if you are doing this for a neural network you can use keras embedding layer and to create the sequence to feed to this embedding layer you can use one hot and padding from the preprocessing packages of course the sequence ...


2

You missed a comma at the end of line 15, replace the part with this code: model = keras.Sequential([ keras.layers.Flatten(input_shape=(28,28)), # comma here keras.layers.Dense(128, activation = 'relu'), # comma here keras.layers.Dense(10, activation = 'softmax') ]) Then it works


2

A Sequential model is not appropriate when: - Your model has multiple inputs or multiple outputs - Any of your layers has multiple inputs or multiple outputs - You need to do layer sharing - You want non-linear topology (e.g. a residual connection, a multi-branch model) The docs suggest that you shouldn't use the Sequential API of Keras when you have such ...


0

It is a correct approach to standardize on your training features. In that way, you ensure not to give any information from the testing set to the training set. About features scaling, if you have too many samples to fit your scaler at once, you could use the partial_fit (see here) method of StandardScaler in sklearn. Load sequentially your training features ...


0

I wrote my own ModelCheckpoint class as I have to call a special save_pretrained method: class ModelCheckpoint(Callback): def __init__(self, freq, directory): super().__init__() self.freq = freq self.directory = directory def on_epoch_begin(self, epoch, logs=None): if self.freq > 0 and epoch % self.freq == 0: ...


1

tf.keras.preprocessing.image_dataset_from_directory Generates a tf.data.Dataset from image files in a directory. ImageDataGenerator.flow_from_directory Takes the path to a directory & generates batches of augmented data. While their return type also differs but the key difference is that flow_from_directory is a method of ImageDataGenerator while ...


0

Include this in your code from tensorflow import keras in place of from tensorflow.python import keras


0

Following up on my comment since I think it will be useful to anyone coming here. "a" can be trainable weight in tf.keras class WeightedSum(layers.Layer): """A custom keras layer to learn a weighted sum of tensors""" def __init__(self, **kwargs): super(WeightedSum, self).__init__(**kwargs) def ...


0

Hope you are applying the preprocessing steps on the dataset that you are using for predict. I remember getting this kind of prediction log time back and that time I think it was something to do with either not applying the same preprocessing pipeline or incorrectly doing the label map Since you are using image generator label mapping should be easy through ...


0

Result of tf.keras.metrics.TopKCategoricalAccuracy() will be between 0 & 1. Default value of the argument k is 5. The result is 1 because for both the samples, the actual value is within the top 5 predictions.


0

The framing of your problem is close to so-called language modeling task. Because your input data is fixed-length samples, you can use a seq2seq model with fixed-size context embedding. What this means is you would essentially have an encoder, Bi-LSTM for example which encodes your input into a fixed representation (by concatenating the final output states ...


0

The issue lies in the mismatch between the standard deviations of train_images vs that of the first hidden layer. The 0.05 comes from the default std of the kernel initializer of the Dense layer. The goal is to get these values closer to each other, Ideally in the same order of magnitude (around or smaller than 1.0). train_images.std() >> 90.0 model....


1

I see two solutions: either you pass a list of dictionnaries to param_grid avoiding irrelevant combinations or you use a single variable in your pipeline for feature_selector__feature__selector_k and classifier__input_shape First solution: you can generate the right list of combinations using something close to this: param_grid = [ { '...


3

So, thank you for clarifying the question. Just to confirm that the question is asking how to set an appropriate threshold for face feature vectors (represented a a and b, for example). What I would recommend is to look at either cosine similarity or euclidean distance, which you have implemented. From here, I would then look the distribution fo the ...


1

Adam works in the same way as SGD does in this regard, it updates the weights at the end of each iteration, so at the end of an epoch multiple weight updates have been applied. Inherently neither Adam nor SGD do anything to counteract the noisy labels, they just try to find the best parameters that minimize a loss function. I don't think anyone can answer ...


1

So you want to identify a person via the similarity of the feature vector of the faces, with some database of known people, right? The similarity measures you said will help you identify the person not evaluate the outcome of that identification. To do this you need a set of people, who you know (i.e. are labelled). Then you need to perform your methodology: ...


0

Less loss means low bias on training set. It always recommended to first aim for a model with low bias so you go and choose "loss_exp-resLayer10". It would have been better if we've loss for validation set because we can't assess the "overfitting". So in case, if your chosen model doesn't perform well on test data then use regularisation ...


1

If you have images of cats only, you could create boundary boxes (BB) of your images. Some BB will have cats an others won't. You will label those BB with cats inside as 1 as the others as 0. This way you can set up a dataset with a binary class. It will be much easier if you already have boundary boxes for the cats in each image since this way it will be ...


0

I suppose you want something like this: image_generator = ImageDataGenerator().flow_from_directory('test_data_path', target_size=(224, 224), shuffle=False) true_labels = image_generator.classes pred_probs = model.predict(image_generator) preds = pred_probs.argmax(axis=-1) print (sum(preds[:,0] ==true_labels)/len(true_labels))


1

The sequential API is the simplest. It allows you to declare a sequence of layers with an single input and a single output. Naturally, this API is a good choice for sequential networks - those where data flows through each layer in sequence. Pros: straightforward to read and write. Cons: Difficult to accommodate multiple inputs/outputs. Cannot define ...


1

The final dense layer's units should be equal to the number of features in your y_train. Suppose your y_train has shape (11784,5) then dense layer's units should be 5 or if y_train has shape (11784,1), then units should be 1. Model expects final dense layer's units equal to the number of output features. You have to identify which features you need in input ...


0

It seems that you are using sorting operations like to calculate p_dist, and these kind of operations do not provide gradient. So the error might not be in the KL function. Hope that helps, Max


0

What is the number of samples? If the dataset has relatively small number of samples and some of them are much harder to classify then the others, it might cause the model to converge on a optimum that misclassifies them. I would recommend checking which samples are misclassified when you achieve this accuracy for each epoch and confirming if they are the ...


0

I had the same problem once when my normalization was "off". I got Nans for all loss functions. Here is what I would do: either drop the scaler.fit(y) and only do the yscale=scaler.transform(y) OR have two different scalers for x and y. Especially if your y values are in a very different number range from your x values. Then the normalization is &...


0

you are correct with using sigmoid+binary CE for multi-label classification problem. On the other hand, try to think about how accuracy would be defined for this problem (https://keras.io/api/metrics/accuracy_metrics/#accuracy-class)? I would use categorical accuracy! Maks


1

I do not think there is a special kind of format that needs to be followed as long as the image is clear and readable, which (imho) it is for your case. Regarding the last 2/3 layers, the final layer is the output with 1 unit, so you pictured it correctly, along as the article mentions the output shape (that is not a multi-output situation). Good luck with ...


0

It sounds like you’re not trying to create a model that can be used outside of the training dataset and instead you’re trying to get your network to memorise the dataset. In other words, you’re aiming to overfit. If that is the case the simplest thing that might work is to take the group of samples your network is getting wrong and upsample them (include ...


1

I agree with @Piotr Rarus (+1); as he said, the no free lunch theorem certainly applies to this. I'd like to add some exploration of the four possible states for perfectly fitting the training data: Impossible due to training function if it is only surjective (onto but not one-to-one). This is of course unlikely, but still feasible. Impossible due to ...


0

You can get that from the weight updates, not sure if it is the best approach -Save the model -Save the weights of the first layer -Load the model and Compile the model with SGD w/o momentum -Set all the weights = that of the previous model -Train with the input and output i.e. the Array for epoch=1 and batch_size=1 -Get the weights again -Calculate the ...


0

Gridsearch cross-validation can be used to learn the hyper-parameters of a prediction function. Consider that learning and testing of the model on the same data is a big mistake. The chance of having a perfect score but failing to predict anything useful on yet-unseen data (i.e., overfitting) is very high when using the same data for learning and testing. It ...


0

The sigmoid activation gives you a number between 0 and 1 (you can consider it as the probability of item i to be of class 1). To get hard predictions (0s and 1s) you just use a rule that says "I consider that the item is predicted positive if the probability is above a certain threshold". For example, for a threshold of 0.5, you just map every ...


1

If you know strict bounds on the sensor output, that would be better than normalizing by the min/max of the dataset. Even if the bounds are not necessarily strict, but simply reasonable, that would suffice. For example, if there are no theoretical bounds on a temperature sensor, you might reasonably impose strict bounds given prior knowledge about its ...


0

Binary crossentropy is for two class problem. You must use sparse categorical crossentropy for your multiclass classification problem and softmax in the last layer not sigmoid. Sigmoid and binary crissentropy is for two class problem while sparse categorical crossentropy and softmax is for multiclass problem.


0

Why would you use a Flatten layer in this? seems like it is already a numerical data. and as @desertnaut mentioned, since this is a regression setup, you should be using mse or mae


0

You should apply and normalize using the total min/max including all the historical data in your dataset. Your model expects the same normalization within each feature across all measurements in that feature. For example sensor_1_day_1 -> 0, 1, 2, 2, 3 sensor_1_day_2 -> 0, .1, .3, .4, .1 normalize sensor_1 for both days with [min,max] of [0,3] and ...


1

Keras needs you to pass one more dimension than it says in the error message: the batch dimension. I.e. If you have a model that requires each sample to have an input shape of (4,) and you have 1000 training samples you need to feed it with an array of (1000, 4). In your case since you want to feed it with just one sample you need to pass a shape of (1, 4). ...


0

inputs = Input(shape=[1]) emb = Embedding(input_dim=cap_shape_dummy.shape[1], output_dim=3)(inputs) x = Flatten()(emb) output = Dense(units=1,activation='sigmoid')(x) model = Model(inputs=inputs,outputs=output)


2

It is usually good to start with a small model because you can then evaluate the contribution of adding layers, etc. Also, Boston dataset is a popular dataset so there are several tutorials showing good neural network architectures, like this one. Concerning your model, here are some notes. The use of sigmoid activation is likely to worsen results, since ...


0

Try this: from tensorflow.keras.layers import * import tensorflow.keras.backend as K import tensorflow as tf BS = 100 x = K.random_normal((BS, 200, 200, 48)) y = K.random_normal((BS, 200, 200, 48)) K.sum(tf.multiply(x, y[:tf.newaxis]), axis=-1, keepdims=True).shape Detailed explanation from here: https://stackoverflow.com/questions/51657476/keras-dot-dot-...


1

So, the question concerns how to go about detecting ships in images, count the number of ships in the image and get the model to predict whether the ship is parked or not. From the problems you have posed, I think it is best that we implement supervised machine learning. This means that we need labelled data. For this, I would recommend taking a sub-sample ...


1

Expected shape of parameter arrays Each layer has two arrays: one for the weights, which has a shape of (num_inputs, num_outpus) one for the biases, which has a shape of (num_outputs) Here the num_inputs is the number of input features to that layer and the num_outputs is the number of outputs from that layer (this is what you select when instantiating a ...


1

A minimum running code by modifying the model building section in the previous code: print('Build model...') model = Sequential() #model.add(LSTM(12, input_shape=( X_train.shape[1:]))) model.add(LSTM(6, dropout=0.2, recurrent_dropout=0.2, input_shape=(None, 1))) model.add(Dense(max_features, activation='softmax')) # try using different optimizers and ...


0

There are two basic approaches to this problem: The performance of the old model was not good enough, you are able to gather much more data and train a new better model You setup an "online model" which continuously learns and improves but is setup very differently. Do you have a specific performance level in mind that you need / want to hit? In ...


1

So, an interesting question asking why a complex model such as the one you have illustrated above is not overfitting (interesting to hear why you would want to achieve this). Firstly, to make sure we are on the same page, overfitting is typically seen when the training loss decrease (accuracy increases), as validation loss remains the same or increases. So, ...


Top 50 recent answers are included