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

Neural network algorithms are stochastic. This means they make use of randomness, such as initializing to random weights, and in turn the same network trained on the same data can produce different results.The random initialization allows the network to learn a good approximation for the function being learned. The most common form of randomness used in ...


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, ...


0

You can find the number of parameters in the layers and accordingly choose number of neurons in next layer. # The fourth convolution tf.keras.layers.Conv2D(128, (3,3), activation='relu'), tf.keras.layers.MaxPooling2D(2,2), Here, number of parameters are: [{(nh – f) / s + 1} X {(nw – f) / s + 1} X nc] here: nh is input height, nw is input width, f is filter ...


0

The Convolution layers do the job of feature extracting. Using those feature the DNN layers try to do the classification task. The 512 layer does the job of a feature selector like which feature is relevant for a class or not while last layer is just calculate sigmoid probability.


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

The reason why tf.tensordot(), tf.math.argmax() doesn't change running regardless of the input size is because they don't make the operations, but rather declare it. It is similar to passing a partial function using functools.partial, the function is not really executed, it just determines it's inputs (or part of it). from functools import partial def ...


0

the soultion is simple , just pass X,Y into thse individual layers and operate as normal here is an example class mymodel(Model): def __init__(self,chandim=-1): #just an example super(mymodel, self).__init__() self.gdn1 = Dense(128 * 16 * 16, activation='relu') self.gbn1 = BatchNormalization(momentum=0.9) self.glr1 ...


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


0

One option is to add TensorFlow Checkpoint which allows for the saving and reloading of training.


2

It really depends on how far you want to go. If you are very serious about GUI apps, PyQt is the only way to go. Qt5 is the gold standard for cross-platform GUI right now. But, for basic applications, you are good to go with Tkinter. I have never used Kivy, and I don't know many people who use it.


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

The first and foremost thing we needs to aware is , from installation perspective is there any micro level relationship between tensorflow and openCV , so that it could help us out in troubleshooting the above issue. But yes this link will help you out in accomplishing your tensorflow/openCV setup installation


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

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 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....


0

1. what is TensorFlow Quantum? Similar to PyTorch, Tensorflow, TFQ is one of the python based framework used to build Quantum Machine Learning models on top of QPU by designing required Circuits and defining applicable gates and measures for the given CNN, RNN etc. models which will sits on top of designed circuits. one can design circuits using cirq 2. ...


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 ...


0

Found out what I was doing wrong. Yes, I built the autoencoder wrong. I didn't think about how I need to flatten the tensor before passing it into a dense layer. Important step but easy to forget... Here is my new model summary in case someone else needs some guidance: Model: "model_9" ...


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 ...


0

but what was being trained when training=True? Let's try to understand BatchNormalization(BN) layer first as it has more elements. TL;DR - γ, β are learned. These are initialized just like normal weights and learned in Backpropagation. May read this crisp and spot-on answer on these parm Stat.SE Formally, BN transforms the activations at a given layer x ...


1

Referring to an answer to a similar question, you don't have any reason to handle unbalance from the beginning. An imbalance of 95:5 isn't that big, I'd start with the regular training and if that doesn't work try more sophisticated things.


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

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

Tensorflow could not found gpu because, the Cuda Toolkit version was 11. But, cuDNN version was 8.2RC + cuda 11. But in Tensorflow-2.2.0 it will work when cuda toolkit and cudnn both has cuda of version 10.1. Cuda 11.0 is not supported.


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


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 ...


1

Right now Tensorflow 2.1 doesn't support CUDA 11.0. Downgrade CUDA to version 10.1 and try again. Reference: https://www.tensorflow.org/install/gpu


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

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 ...


0

for macosx/linux tensorflow gpu installation - https://www.youtube.com/watch?v=MpUvdLD932c&list=PLjy4p-07OYzulelvJ5KVaT2pDlxivl_BN&index=8. for windows 10 - https://www.youtube.com/watch?v=qrkEYf-YDyI&list=PLjy4p-07OYzulelvJ5KVaT2pDlxivl_BN&index=9


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

The 10 outputs came from the fact that you have 10 neurons in the final layer of your network. If you change your model to model = tf.keras.models.Sequential([ tf.keras.layers.Dense(10, activation='relu'), tf.keras.layers.Dense(10, activation='relu'), tf.keras.layers.Dense(10, activation='relu'), tf.keras.layers.Dense(1, activation='relu') ]) ...


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 ...


0

because dropout applies to the input layer What you said is True in terms of behavior but Dropout is implemented as a separate layer i.e. keras.layers.Dropout. We can treat it like any other layer. model = keras.Sequential() model.add(keras.layers.Dense(200, input_shape=(50,), activation="tanh")) model.add(keras.layers.Dropout(0.3)) model.add(...


1

When talking about feed forward neural networks one distinguishes between input layer, hidden layers and output layer. Usually you have a single input and output layer and one or more hidden layers. In your case, the input layer with 20 input neurons is not explicitly mentioned in the code but its still there. Further, there is one hidden layer with 200 ...


1

I think your understanding of the output vector is not correct (Not just for Neural Network but any Model) We don't encode the output to reduce the dimension. Output has not much contribution on the RAM and computation, it's the input size and dimension. Simple OHE Or just the label encoding will work(Loss function will change as per the case) What you ...


1

I think your best option is to use the cloud, since your PC is not capable, and has limited resources. You can set up a Google Colab or Kaggle account to run Jupyter notebooks online. They will support most libraries, including Tensorflow, Keras, and Pytorch. Both will also provide limited GPU resources. Google Colab has a free version you can use, just ...


0

SparseCategoricalCrossentropy is a class while sparse_categorical_crossentropy is a function. SparseCategoricalCrossentropy -> You create an instance of this class and then pass the true values and predicted values. sparse_categorical_crossentropy -> You pass the true and predicted values just as you would do with any other function.


4

SparseCategoricalCrossentropy is a class. So you have to define a object first then you can compute the loss using it. scce = tf.keras.losses.SparseCategoricalCrossentropy() scce(y_true, y_pred).numpy() While sparse_categorical_crossentropy is merely a function which can be directly used to compute cost. loss = tf.keras.losses....


0

This should work - - Make your last layer as second last layer with activation='relu' - Assign weights from the previous model - Add a layer on top of it with 15 Neurons and activation='softmax'.


0

It will not It's about using a model which was trained on thousands of Classes on Millions of images of ImageNet. Chances are very high that most of the classes you have in your dataset is already there. In general, if you trained a model on a super-class (e.g. vehicle), then you may reuse it to classify the Car variant(Utilizing its initial layers). Point ...


0

Artificial Neural Networks are like a black box learning system. There is no known, or generally agreed upon, method that dictates what each weight represents or means for a given learning problem. Its internal representation of the problem is opaque to the architect. In fact, the final trained weights are very closely tied to the neural network architecture ...


0

OP evidently figured out the issue himself and posted solution here. Basically, the class label integers in his dataset for a binary classification problem appeared as [0,4], instead of [0,1]. If class labels are integers, they must be consecutive values(e.g, [0,1] for two labels, [0,1,2,3] for four labels).


0

Okay, it was a very stupid mistake. As the error message states, an input list is required. So replacing this part of the code: tf_string = tf.py_function(serialize_one_image, img, tf.string) to this tf_string = tf.py_function(serialize_one_image, [img], tf.string) i.e. wrapping the imgobject into a list solved the problem. Now it works as expected. Thanks ...


Top 50 recent answers are included