Keras flowFromDirectory get file names as they are being generated

Yes is it possible, at least with version 2.0.4 (don’t know about earlier version). The instance of ImageDataGenerator().flow_from_directory(…) has an attribute with filenames which is a list of all the files in the order the generator yields them and also an attribute batch_index. So you can do it like this: datagen = ImageDataGenerator() gen = … Read more

record the computation time for each epoch in Keras during model.fit()

Try the following callback: class TimeHistory(keras.callbacks.Callback): def on_train_begin(self, logs={}): self.times = [] def on_epoch_begin(self, batch, logs={}): self.epoch_time_start = time.time() def on_epoch_end(self, batch, logs={}): self.times.append(time.time() – self.epoch_time_start) Then: time_callback = TimeHistory() model.fit(…, callbacks=[…, time_callback],…) times = time_callback.times In this case times should store the epoch computation times.

InvalidArgumentError: cannot compute MatMul as input #0(zero-based) was expected to be a float tensor but is a double tensor [Op:MatMul]

Part 1: The problem is indeed the datatype of your input. By default your keras model expects float32 but you are passing a float64. You can either change the dtype of the model or change the input to float32. To change your model: def make_model(): net = tf.keras.Sequential() net.add(tf.keras.layers.Dense(4, activation=’relu’, dtype=”float32″)) net.add(tf.keras.layers.Dense(4, activation=’relu’)) net.add(tf.keras.layers.Dense(1)) return … Read more

How does the Flatten layer work in Keras?

The Flatten() operator unrolls the values beginning at the last dimension (at least for Theano, which is “channels first”, not “channels last” like TF. I can’t run TensorFlow in my environment). This is equivalent to numpy.reshape with ‘C’ ordering: ā€˜C’ means to read / write the elements using C-like index order, with the last axis … Read more

How to load only specific weights on Keras

If your first 9 layers are consistently named between your original trained model and the new model, then you can use model.load_weights() with by_name=True. This will update weights only in the layers of your new model that have an identically named layer found in the original trained model. The name of the layer can be … Read more

Running Tensorflow in Jupyter Notebook

I came up with your case. This is how I sort it out Install Anaconda Create a virtual environment – conda create -n tensorflow Go inside your virtual environment – (on macOS/Linux:) source activate tensorflow (on Windows: activate tensorflow) Inside that install tensorflow. You can install it using pip Finish install So then the next … Read more

400% higher error with PyTorch compared with identical Keras model (with Adam optimizer)

The problem here is unintentional broadcasting in the PyTorch training loop. The result of a nn.Linear operation always has shape [B,D], where B is the batch size and D is the output dimension. Therefore, in your mean_squared_error function ypred has shape [32,1] and ytrue has shape [32]. By the broadcasting rules used by NumPy and … Read more

How to calculate optimal batch size?

From the recent Deep Learning book by Goodfellow et al., chapter 8: Minibatch sizes are generally driven by the following factors: Larger batches provide a more accurate estimate of the gradient, but with less than linear returns. Multicore architectures are usually underutilized by extremely small batches. This motivates using some absolute minimum batch size, below … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)