keras

Keras model summary incorrect

删除回忆录丶 提交于 2021-02-11 15:51:05
问题 I am doing data augmentation using data_gen=image.ImageDataGenerator(rotation_range=20,width_shift_range=0.2,height_shift_range=0.2, zoom_range=0.15,horizontal_flip=False) iter=data_gen.flow(X_train,Y_train,batch_size=64) data_gen.flow() needs a rank 4 data matrix, so the shape of X_train is (60000, 28, 28, 1) . We need to pass the same shape i.e (60000, 28, 28, 1) while defining the architecture of the model as follows; model=Sequential() model.add(Dense(units=64,activation='relu',kernel

Keras model summary incorrect

﹥>﹥吖頭↗ 提交于 2021-02-11 15:48:44
问题 I am doing data augmentation using data_gen=image.ImageDataGenerator(rotation_range=20,width_shift_range=0.2,height_shift_range=0.2, zoom_range=0.15,horizontal_flip=False) iter=data_gen.flow(X_train,Y_train,batch_size=64) data_gen.flow() needs a rank 4 data matrix, so the shape of X_train is (60000, 28, 28, 1) . We need to pass the same shape i.e (60000, 28, 28, 1) while defining the architecture of the model as follows; model=Sequential() model.add(Dense(units=64,activation='relu',kernel

Can not load model weights saved to GCP with keras.save_weights. Need to transfer to new bucket to load weights

余生颓废 提交于 2021-02-11 15:36:00
问题 I am training on Google Colab with data and model weights loaded from/save to GCP. I am using Keras callbacks to save the weights to GCP. This is what the callback looks like callbacks = [tf.keras.callbacks.ModelCheckpoint(filepath='gs://mybucket/'+ 'savename' + '_loss_{loss:.2f}', monitor='loss', verbose=1, save_weights_only=True, save_freq='epoch')] The training saves the model weights successfully to my GCP bucket, but when I try to load those weights in a new session, the cell just hangs,

ValueError: Input 0 is incompatible with layer conv2d_5: expected ndim=4, found ndim=2

烂漫一生 提交于 2021-02-11 15:19:09
问题 I am trying to build a CNN network and wuld like to probe the layer dimention using output_shape. But it's giving me an error as follows: ValueError: Input 0 is incompatible with layer conv2d_5: expected ndim=4, found ndim=2 Below is the code I am trying to execute from keras.layers import Activation model = Sequential() model.add(Convolution2D(32, 3, 3, activation='relu', input_shape=(1,28,28))) print(model.output_shape) 回答1: You can check if by default the number of channels is specified at

Output of Keras predict method has the wrong shape when using Google Colab's tpu strategy

ぃ、小莉子 提交于 2021-02-11 15:14:34
问题 I made the following architecture Layer (type) Output Shape Param # ================================================================= embedding_7 (Embedding) (None, 50, 64) 512000 _________________________________________________________________ bidirectional_5 (Bidirection (None, 200) 132000 _________________________________________________________________ dense_9 (Dense) (None, 1) 201 ================================================================= Total params: 644,201 Trainable params:

Keras not running in multiprocessing

不打扰是莪最后的温柔 提交于 2021-02-11 14:18:15
问题 I'm trying to run my keras model using multiprocessing due to GPU OOM issue. I loaded all libraries and set up the model within the function for multiprocessing as below: When I execute this code, it gets stuck at history = q.get() , which is multiprocessing.Queue.get() . And when I remove all the code related to multiprocessing.Queue() , the code execution ends as soon as I execute the code, which I suspect that the code is not working. Even a simple print() function didn't show an output.

tensorflow backend error. AttributeError: module 'tensorflow' has no attribute 'name_scope'

。_饼干妹妹 提交于 2021-02-11 13:51:19
问题 I'm using Version: 2.1.0 of TensorFlow and 2.3.1 of keras. While importing any module of keras i'm facing below tensorflow back-end error. import pandas as pd, numpy as np, os, re, json, math, time from keras.models import Sequential from keras.layers import Dense from keras.wrappers.scikit_learn import KerasRegressor from sklearn.model_selection import cross_val_score from sklearn.model_selection import KFold from sklearn.preprocessing import StandardScaler from sklearn.pipeline import

AttributeError: 'numpy.ndarray' object has no attribute 'id'

大憨熊 提交于 2021-02-11 13:42:08
问题 I am creating a sklearn pipeline that consists of 3 steps: Transforms pandas dataframe into 3D array Transforms 3D array into recurrence plot (image) Trains an image classification model using Keras This is my initial data set: train_df - pandas dataframe id cycle s1 1 1 0.05 1 2 0.04 1 3 0.05 1 4 0.05 2 1 0.02 2 2 0.03 y_train array([[1., 0., 0.], [1., 0., 0.], ... [1., 0., 0.]], dtype=float32) When I run my current code (see below), I get the following error: AttributeError: 'numpy.ndarray'

BERT sentence embeddings: how to obtain sentence embeddings vector

天大地大妈咪最大 提交于 2021-02-11 13:41:14
问题 I'm using the module bert-for-tf2 in order to wrap BERT model as Keras layer in Tensorflow 2.0 I've followed your guide for implementing BERT model as Keras layer. I'm trying to extract embeddings from a sentence; in my case, the sentence is "Hello" I have a question about the output of the model prediction; I've written this model: model_word_embedding = tf.keras.Sequential([ tf.keras.layers.Input(shape=(4,), dtype='int32', name='input_ids'), bert_layer ]) model_word_embedding .build(input

LSTM produces identical forecast for each input

不羁的心 提交于 2021-02-11 13:25:36
问题 I've been working on reproducing a CNN-LSTM model for PV power forecasting from literature for the past four weeks for my Master Thesis in Energy Science (http://www.mdpi.com/2076-3417/8/8/1286). However I've been stuck on a seemingly simple issue: Any configuration of LSTM model that I've tried yields one of two things: Rediculous output, makes no sense whatsoever (flat line, complete stochasticity, negative values, you name it) Exactly the same (very believable) PV power forecast. I've done