keras

Error when checking input: expected embedding_1_input to have shape (4,) but got array with shape (1,)

混江龙づ霸主 提交于 2021-02-10 14:40:36
问题 I use pretrained embedding vectors for my keras model. Before I did it everything worked and now I get this error: ValueError: Error when checking input: expected embedding_1_input to have shape (4,) but got array with shape (1,) Maybe somebody can help me, what I do wrong here. I am not sure if I did correct model.fit and model.evaluate. Maybe there is a problem? import csv import numpy as np np.random.seed(42) from keras.models import Sequential, Model from keras.layers import * from random

How to get layer weight while training?

只愿长相守 提交于 2021-02-10 14:35:23
问题 I have a model and I would like to get the weight matrix of a specific layer to use it while defining custom loss function. Is there any way to get a weight of specific layer, inside the model? P.S. I am currently working with tensorflow 2, and keras functional API. I tested How do I get the weights of a layer in Keras? approach, but it did not work. P.P.S. By using the above described approach, I get the following error: AttributeError Traceback (most recent call last) <ipython-input-26

Dataset shape mismatch Conv1D input layer

心不动则不痛 提交于 2021-02-10 14:33:28
问题 Trying to set up a Conv1D layer to be the input layer in keras. The dataset is 1000 timesteps, and each timestep has 1 feature. After reading a bunch of answers I reshaped my dataset to be in the following format of (n_samples, timesteps, features), which corresponds to the following in my case: train_data = (78968, 1000, 1) test_data = (19742, 1000, 1) train_target = (78968,) test_target = (19742,) I later create and compile the code using the following lines model = Sequential() model.add

CNN loss with multiple outputs?

寵の児 提交于 2021-02-10 14:33:08
问题 I have the following model def get_model(): epochs = 100 learning_rate = 0.1 decay_rate = learning_rate / epochs inp = keras.Input(shape=(64, 101, 1), name="inputs") x = layers.Conv2D(128, kernel_size=(3, 3), strides=(3, 3), padding="same")(inp) x = layers.Conv2D(256, kernel_size=(3, 3), strides=(3, 3), padding="same")(x) x = layers.Flatten()(x) x = layers.Dense(150)(x) x = layers.Dense(150)(x) out1 = layers.Dense(40000, name="sf_vec")(x) out2 = layers.Dense(128, name="ls_weights")(x) model =

Shape error when passed custom LSTM

六月ゝ 毕业季﹏ 提交于 2021-02-10 14:21:01
问题 I have been trying to custom a LSTM layer for further improvement. But an error which seems like normal raised at pooling layer after my custom LSTM. My environment is: win 10 keras 2.2.0 python 3.6 Traceback (most recent call last): File "E:/PycharmProjects/dialogResearch/dialog/classifier.py", line 60, in model = build_model(word_dict, args.max_len, args.max_sents, args.embedding_dim) File "E:\PycharmProjects\dialogResearch\dialog\model\keras_himodel.py", line 177, in build_model l_dense =

Unable to load .h5 file made in Google Colab to Jupyter Notebook [duplicate]

∥☆過路亽.° 提交于 2021-02-10 14:16:25
问题 This question already has answers here : Unexpected keyword argument 'ragged' in Keras (2 answers) Closed last month . I tried a code for Face mask detect and alert system and I am getting an error regarding the same. I trained the model in Google Collaboratory and ran the following code in Jupyter Notebook. The code is as follows: # Import necessary libraries from keras.models import load_model import cv2 import numpy as np import tkinter from tkinter import messagebox import smtplib #

What's the difference between attrubutes 'trainable' and 'training' in BatchNormalization layer in Keras Tensorfolow?

回眸只為那壹抹淺笑 提交于 2021-02-10 12:52:46
问题 According to the official documents from tensorflow: About setting layer.trainable = False on a `BatchNormalization layer: The meaning of setting layer.trainable = False is to freeze the layer, i.e. its internal state will not change during training: its trainable weights will not be updated during fit() or train_on_batch(), and its state updates will not be run. Usually, this does not necessarily mean that the layer is run in inference mode (which is normally controlled by the training

keras mnist.load_data() is superslow and throw an error after some times

醉酒当歌 提交于 2021-02-10 12:30:11
问题 here is the whole code I use import os import numpy as np import matplotlib.pyplot as plt from tqdm import tqdm from keras.layers import Input from keras.models import Model, Sequential from keras.layers.core import Dense, Dropout from keras.layers.advanced_activations import LeakyReLU from keras.datasets import mnist from keras.optimizers import Adam from keras import initializers os.environ["KERAS_BACKEND"] = "tensorflow" np.random.seed(10) random_dim = 100 def load_mnist_data(): # load the

How to implement an adaptive loss in Keras?

家住魔仙堡 提交于 2021-02-10 12:01:02
问题 I am trying to use Keras to implement the work done in A General and Adaptive Robust Loss Function. The author provides tensorflow code that works the hard details. I am just trying to use his prebuilt function in Keras. His custom loss function is learning a parameter 'alpha' that controls the shape of the loss function. I would like to track 'alpha' in addition to the loss during training. I am somewhat familiar with Keras custom loss functions and using wrappers, but I am not entirely sure

Low validation accuracy with good training accuracy - keras imagedatagenerator flow_from_directory categorical classification

狂风中的少年 提交于 2021-02-10 07:27:11
问题 I am trying to classify the Kaggle 10k dog images to 120 breeds using Keras and ResNet50. Due to memory constraints at Kaggle (14gb ram) - I have to use the ImageDataGenerator that feeds the images to the model and also allows data augmentation - in real time. The base convoluted ResNet50 model: conv_base = ResNet50(weights='imagenet', include_top=False, input_shape=(224,224, 3)) My model: model = models.Sequential() model.add(conv_base) model.add(layers.Flatten()) model.add(layers.Dense(256,