keras

Merging Two Trained Networks for Inferencing Sequentially

ε祈祈猫儿з 提交于 2021-01-29 09:21:37
问题 I am trying to merge two trained neural networks. I have two trained Keras model files A and B. Model A is for image super-resolution and model B is for image colorization. I am trying to merge two trained networks so that I can inference SR+colorization faster. (I am not willing to use a single network to accomplish both SR and colorization tasks. I need to use two different networks for SR and colorization tasks.) Any tips on how to merge two Keras neural networks? 回答1: As long a the shape

Keras Functional API and activations

徘徊边缘 提交于 2021-01-29 09:20:31
问题 I'm having problems when trying to use activations with Keras Functional API. My initial goal was to have choice between relu and leaky relu, so I came up with the following piece of code: def activation(x, activation_type): if activation_type == 'leaky_relu': return activations.relu(x, alpha=0.3) else: return activations.get(activation_type)(x) # building the model inputs = keras.Input(input_shape, dtype='float32') x = Conv2D(filters, (3, 3), padding='same')(inputs) x = activation(x, 'relu')

Get confusion matrix from a Keras model

夙愿已清 提交于 2021-01-29 09:13:15
问题 I have the following NN model using Keras: import numpy as np from keras import Sequential from keras.layers import Dense path = 'pima-indians-diabetes.data.csv' dataset = np.loadtxt(path, delimiter=",") X = dataset[:,0:8] Y = dataset[:,8] X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.2) model = Sequential() model.add(Dense(16, input_dim=8, activation='relu')) model.add(Dense(32, activation='relu')) model.add(Dense(1, activation='sigmoid')) model.compile(loss='binary

Get confusion matrix from a Keras model

拟墨画扇 提交于 2021-01-29 09:09:29
问题 I have the following NN model using Keras: import numpy as np from keras import Sequential from keras.layers import Dense path = 'pima-indians-diabetes.data.csv' dataset = np.loadtxt(path, delimiter=",") X = dataset[:,0:8] Y = dataset[:,8] X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.2) model = Sequential() model.add(Dense(16, input_dim=8, activation='relu')) model.add(Dense(32, activation='relu')) model.add(Dense(1, activation='sigmoid')) model.compile(loss='binary

How to compute number of weights of CNN?

孤街醉人 提交于 2021-01-29 08:55:01
问题 How can we compute number of weights considering a convolutional neural network that is used to classify images into two classes : INPUT: 100x100 gray-scale images. LAYER 1: Convolutional layer with 60 7x7 convolutional filters (stride=1, valid padding). LAYER 2: Convolutional layer with 100 5x5 convolutional filters (stride=1, valid padding). LAYER 3: A max pooling layer that down-samples Layer 2 by a factor of 4 (e.g., from 500x500 to 250x250) LAYER 4: Dense layer with 250 units LAYER 5:

Why tensorflow is slower with GPU instead of CPU?

假如想象 提交于 2021-01-29 08:54:48
问题 This is a really simple neural network: n_pts = 500000 np.random.seed(0) Xa = np.array([np.random.normal(13, 2, n_pts), np.random.normal(12, 2, n_pts)]).T Xb = np.array([np.random.normal(8, 2, n_pts), np.random.normal(6, 2, n_pts)]).T X = np.vstack((Xa, Xb)) y = np.matrix(np.append(np.zeros(n_pts), np.ones(n_pts))).T # Create a new Keras model model = Sequential() model.add(Dense(units=1, input_shape=(2,), activation='sigmoid')) adam = Adam(lr=0.1) model.compile(adam, loss='binary

LSTM Time series shifted predictions on stock market close price

痞子三分冷 提交于 2021-01-29 08:46:45
问题 I have developed a RNN system to predict the stock market close price based on several features. I removed the close price from the X and moved it to Y. I also made a shift on Y and dropna() to make sure that all features of day X(t) is equals to Y(t+future_days). Thus means that the features for today will predict the close price of today plus future_days. From the images bellow, the first future_days = 20 and the second future_days = 5. The prediction is shifted the number of future_days in

how to enable GPU visible for ML runtime environment on databricks?

隐身守侯 提交于 2021-01-29 08:32:10
问题 I am trying to run some TensorFlow (2.2) example code on databricks/GPU (p2.xlarge) with environment as: 6.6 ML, spark 2.4.5, GPU, Scala 2.11 Keras version : 2.2.5 nvidia-smi NVIDIA-SMI 440.64.00 Driver Version: 440.64.00 CUDA Version: 10.2 I have checked https://docs.databricks.com/applications/deep-learning/single-node-training/tensorflow.html#install-tensorflow-22-on-databricks-runtime-66-ml&language-GPU But, I do not want to run the shell commands every time the databricks GPU clusters is

How to zero pad on both sides and encode the sequence into one hot in keras?

别说谁变了你拦得住时间么 提交于 2021-01-29 08:18:17
问题 I have text data as follows. X_train_orignal= np.array(['OC(=O)C1=C(Cl)C=CC=C1Cl', 'OC(=O)C1=C(Cl)C=C(Cl)C=C1Cl', 'OC(=O)C1=CC=CC(=C1Cl)Cl', 'OC(=O)C1=CC(=CC=C1Cl)Cl', 'OC1=C(C=C(C=C1)[N+]([O-])=O)[N+]([O-])=O']) As it is evident that different sequences have different length. How can I zero pad the sequence on both sides of the sequence to some maximum length. And then convert each sequence into one hot encoding based on each characters? Try: I used the following keras API but it doesn't

tf.keras.Model save: “AssertionError: Tried to export a function which references untracked object Tensor”

一曲冷凌霜 提交于 2021-01-29 08:12:32
问题 I'm running this Tensorflow NMT tutorial: https://github.com/tensorflow/addons/blob/master/docs/tutorials/networks_seq2seq_nmt.ipynb When I try to save the decoder: decoder.save('decoder') , I get: AssertionError: Tried to export a function which references untracked object Tensor("LuongAttention/memory_layer/Tensordot:0", shape=(1024, 23, 256), dtype=float32).TensorFlow objects (e.g. tf.Variable) captured by functions must be tracked by assigning them to an attribute of a tracked object or