Why is TensorFlow 2 much slower than TensorFlow 1?

It’s been cited by many users as the reason for switching to Pytorch, but I’ve yet to find a justification/explanation for sacrificing the most important practical quality, speed, for eager execution. Below is code benchmarking performance, TF1 vs. TF2 – with TF1 running anywhere from 47% to 276% faster. My question is: what is it, … Read more

Tensorflow 2.0 – AttributeError: module ‘tensorflow’ has no attribute ‘Session’

When I am executing the command sess = tf.Session() in Tensorflow 2.0 environment, I am getting an error message as below: Traceback (most recent call last): File “<stdin>”, line 1, in <module> AttributeError: module ‘tensorflow’ has no attribute ‘Session’ System Information: OS Platform and Distribution: Windows 10 Python Version: 3.7.1 Tensorflow Version: 2.0.0-alpha0 (installed with … Read more

Where do I call the BatchNormalization function in Keras?

If I want to use the BatchNormalization function in Keras, then do I need to call it once only at the beginning? I read this documentation for it: http://keras.io/layers/normalization/ I don’t see where I’m supposed to call it. Below is my code attempting to use it: model = Sequential() keras.layers.normalization.BatchNormalization(epsilon=1e-06, mode=0, momentum=0.9, weights=None) model.add(Dense(64, input_dim=14, … Read more

Why binary_crossentropy and categorical_crossentropy give different performances for the same problem?

I’m trying to train a CNN to categorize text by topic. When I use binary cross-entropy I get ~80% accuracy, with categorical cross-entropy I get ~50% accuracy. I don’t understand why this is. It’s a multiclass problem, doesn’t that mean that I have to use categorical cross-entropy and that the results with binary cross-entropy are … Read more

Keras, How to get the output of each layer?

I have trained a binary classification model with CNN, and here is my code model = Sequential() model.add(Convolution2D(nb_filters, kernel_size[0], kernel_size[1], border_mode=”valid”, input_shape=input_shape)) model.add(Activation(‘relu’)) model.add(Convolution2D(nb_filters, kernel_size[0], kernel_size[1])) model.add(Activation(‘relu’)) model.add(MaxPooling2D(pool_size=pool_size)) # (16, 16, 32) model.add(Convolution2D(nb_filters*2, kernel_size[0], kernel_size[1])) model.add(Activation(‘relu’)) model.add(Convolution2D(nb_filters*2, kernel_size[0], kernel_size[1])) model.add(Activation(‘relu’)) model.add(MaxPooling2D(pool_size=pool_size)) # (8, 8, 64) = (2048) model.add(Flatten()) model.add(Dense(1024)) model.add(Activation(‘relu’)) model.add(Dropout(0.5)) model.add(Dense(2)) # define a … Read more

Keras input explanation: input_shape, units, batch_size, dim, etc

For any Keras layer (Layer class), can someone explain how to understand the difference between input_shape, units, dim, etc.? For example the doc says units specify the output shape of a layer. In the image of the neural net below hidden layer1 has 4 units. Does this directly translate to the units attribute of the … Read more