keras

从零开始学Keras(三)

依然范特西╮ 提交于 2021-02-18 01:46:23
点击上方“ 计算机视觉cv ”即可“进入公众号” 重磅干货第一时间送达 计算机视觉cv 【 导读 】Keras是一个由Python编写的开源人工神经网络库,可以作为Tensorflow、和Theano的高阶应用程序接口,进行深度学习模型的设计、调试、评估、应用和可视化。本系列将教你如何从零开始学Keras,从搭建神经网络到项目实战,手把手教你精通Keras。相关内容参考《Python深度学习》这本书。 多分类问题   本节你会构建一个网络,将路透社新闻划分为 46 个互斥的主题。因为有多个类别,所以这是多分类(multiclass classification)问题的一个例子。因为每个数据点只能划分到一个类别,所以更具体地说,这是单标签、多分类(single-label, multiclass classification)问题的一个例子。如果每个数据点可以划分到多个类别(主题),那它就是一个多标签、多分类(multilabel, multiclass classification)问题。 路透社数据集   本节使用路透社数据集,它包含许多短新闻及其对应的主题,由路透社在 1986 年发布。它是一个简单的、广泛使用的文本分类数据集。它包括 46 个不同的主题:某些主题的样本更多,但训练集中每个主题都有至少 10 个样本。   与 IMDB 和 MNIST 类似,路透社数据集也内置为

Keras EarlyStopping: Which min_delta and patience to use?

流过昼夜 提交于 2021-02-17 19:13:56
问题 I am new to deep learning and Keras and one of the improvement I try to make to my model training process is to make use of Keras's keras.callbacks.EarlyStopping callback function. Based on the output from training my model, does it seem reasonable to use the following parameters for EarlyStopping ? EarlyStopping(monitor='val_loss', min_delta=0.0001, patience=5, verbose=0, mode='auto') Also, why does it appear to be stopped sooner than it should if it was to wait for 5 consecutive epochs

Keras EarlyStopping: Which min_delta and patience to use?

﹥>﹥吖頭↗ 提交于 2021-02-17 19:12:39
问题 I am new to deep learning and Keras and one of the improvement I try to make to my model training process is to make use of Keras's keras.callbacks.EarlyStopping callback function. Based on the output from training my model, does it seem reasonable to use the following parameters for EarlyStopping ? EarlyStopping(monitor='val_loss', min_delta=0.0001, patience=5, verbose=0, mode='auto') Also, why does it appear to be stopped sooner than it should if it was to wait for 5 consecutive epochs

why set return_sequences=True and stateful=True for tf.keras.layers.LSTM?

为君一笑 提交于 2021-02-17 16:38:22
问题 I am learning tensorflow2.0 and follow the tutorial. In the rnn example, I found the code: def build_model(vocab_size, embedding_dim, rnn_units, batch_size): model = tf.keras.Sequential([ tf.keras.layers.Embedding(vocab_size, embedding_dim, batch_input_shape=[batch_size, None]), tf.keras.layers.LSTM(rnn_units, return_sequences=True, stateful=True, recurrent_initializer='glorot_uniform'), tf.keras.layers.Dense(vocab_size) ]) return model My question is: why the code set the argument return

why set return_sequences=True and stateful=True for tf.keras.layers.LSTM?

不问归期 提交于 2021-02-17 16:36:26
问题 I am learning tensorflow2.0 and follow the tutorial. In the rnn example, I found the code: def build_model(vocab_size, embedding_dim, rnn_units, batch_size): model = tf.keras.Sequential([ tf.keras.layers.Embedding(vocab_size, embedding_dim, batch_input_shape=[batch_size, None]), tf.keras.layers.LSTM(rnn_units, return_sequences=True, stateful=True, recurrent_initializer='glorot_uniform'), tf.keras.layers.Dense(vocab_size) ]) return model My question is: why the code set the argument return

Issues using Keras np_utils.to_categorical

扶醉桌前 提交于 2021-02-17 14:56:16
问题 I'm trying to make an array of one-hot vector of integers into an array of one-hot vector that keras will be able to use to fit my model. Here's the relevant part of the code: Y_train = np.hstack(np.asarray(dataframe.output_vector)).reshape(len(dataframe),len(output_cols)) dummy_y = np_utils.to_categorical(Y_train) Below is an image showing what Y_train and dummy_y actually are. I couldn't find any documentation for to_categorical that could help me. Thanks in advance. 回答1: np_utils.to

How to avoid overfitting on a simple feed forward network

放肆的年华 提交于 2021-02-17 14:53:46
问题 Using the pima indians diabetes dataset I'm trying to build an accurate model using Keras. I've written the following code: # Visualize training history from keras import callbacks from keras.layers import Dropout tb = callbacks.TensorBoard(log_dir='/.logs', histogram_freq=10, batch_size=32, write_graph=True, write_grads=True, write_images=False, embeddings_freq=0, embeddings_layer_names=None, embeddings_metadata=None) # Visualize training history from keras.models import Sequential from

How to use Keras' predict_on_batch in tf.data.Dataset.map()?

只谈情不闲聊 提交于 2021-02-17 04:55:54
问题 I would like to find a way to use Keras' predict_on_batch inside tf.data.Dataset.map() in TF2.0. Let's say I have a numpy dataset n_data = 10**5 my_data = np.random.random((n_data,10,1)) my_targets = np.random.randint(0,2,(n_data,1)) data = ({'x_input':my_data}, {'target':my_targets}) and a tf.keras model x_input = Input((None,1), name = 'x_input') RNN = SimpleRNN(100, name = 'RNN')(x_input) dense = Dense(1, name = 'target')(RNN) my_model = Model(inputs = [x_input], outputs = [dense]) my

Keras Sequential model input shape

别来无恙 提交于 2021-02-17 02:52:59
问题 I want to train a neural net based on a numpy array with 4 entries as the X-data and another array with one entry as the y-data. X_train = [x1, x2, x3, x4] y_train = [y1] A rather simple thing I thought, but I can't get the input shape to work. I also found very little information about how the input shape works: Do you have to specify only the X data? What about the y data? I already tried setting input_dim = 4, since that was the first logical thing to do but I got the following Error:

Name of a custom fuction in Keras model R

自作多情 提交于 2021-02-17 01:51:40
问题 I have created a custom loss function: RMSE= function(y_true,y_pred){ k_sqrt(k_mean(k_square(y_pred-y_true))) } And it works fine but when I run: model$loss Get: <function make_python_function.<locals>.python_function at 0x0000026A51F5c80> Instead of the name of the loss function, like when I used for example 'mse' model$loss "mse" What should I add to my custom function to be able to get the name? 来源: https://stackoverflow.com/questions/60599127/name-of-a-custom-fuction-in-keras-model-r