tf.keras

How to combine multiple datasets into one dataset?

断了今生、忘了曾经 提交于 2019-12-24 11:22:31
问题 Suppose I have 3 tfrecord files, namely neg.tfrecord , pos1.tfrecord , pos2.tfrecord . I use dataset = tf.data.TFRecordDataset(tfrecord_file) this code creates 3 Dataset objects. My batch size is 400, including 200 neg data, 100 pos1 data, and 100 pos2 data. How can I get the desired dataset? I will use this dataset object in keras.fit() (Eager Execution). My tensorflow's version is 1.13.1. Before, I tried to get the iterator for each dataset, and then manually concat after getting the data,

LSTM - Use deltaTime as a feature? How to handle irregular timestamps?

家住魔仙堡 提交于 2019-12-24 04:48:11
问题 I'm trying to create a LSTM for classification of data sequences. The data structure of every training input that I would use is: [[ [deltaX,deltaY,deltaTime], [deltaX,deltaY,deltaTime],... ],class] Where deltaX and deltaY reflect the change of X and Y in a given time deltaTime. deltaTime is not the same everytime, it can vary from 40ms to 50ms to sometimes 1000ms. The 'class' at the end is a binary classification, that can be either 0 or 1. Question 1 (regular LSTM): Should I include

The established way to use TF Dataset API in Keras is to feed `model.fit` with `make_one_shot_iterator()`, But this iterator only good for one Epoch

跟風遠走 提交于 2019-12-13 03:49:55
问题 Edit: To clarify why this question is different from the suggested duplicates, this SO question follows up on those suggested duplicates, on what exactly is Keras doing with the techniques described in those SO questions. The suggested duplicates specify using a dataset API make_one_shot_iterator() in model.fit , my follow up is that make_one_shot_iterator() can only go through the dataset once, however in the solutions given, several epochs are specified. This is a follow up to these SO

Entity Embedding of Categorical within Time Series Data and LSTM

放肆的年华 提交于 2019-12-13 03:19:15
问题 I'm trying to solve a time series problem. In short, for each customer and material (SKU code), I have different orders placed in the past. I need to build a model that predict the number of days before the next order for each customer and material. What I'm trying to do is to build an LSTM model in Keras, where for each customer and material I have a 50 max padded timesteps of history, and I'm using a mix of numeric (# of days since previous order, AVG days between orders in last 60 days etc

Keras backend mean function: “ 'float' object has no attribute 'dtype' ”?

北城以北 提交于 2019-12-13 02:49:55
问题 I am trying to introduce a new kernel regularize for a network using Keras. But, it gives me the error: 'float' object has no attribute 'dtype' How can I fix it? I found the code here: KL divergence in keras(tensorflow backend) Here is my code: from keras import backend as K kullback_leibler_divergence = keras.losses.kullback_leibler_divergence def kl_divergence_regularizer(inputs): means = K.mean((inputs)) return 0.5 *(0.01 * (kullback_leibler_divergence(0.05, means) + kullback_leibler

How do I create a regression model with multiple outputs in tf.keras?

时间秒杀一切 提交于 2019-12-12 01:00:11
问题 I'm attempting to train a regression model to predict attributes of music such as BPM. The model takes in spectrograms of audio snippets that are 256x128px png files and outputs a couple continuous values. I have the following code so far that I have developed based upon this guide on the tensorflow website: import tensorflow as tf import os import random import pathlib AUTOTUNE = tf.data.experimental.AUTOTUNE TRAINING_DATA_DIR = r'specgrams' def gen_model(): model = tf.keras.models

How load a model and its constants through just importing a module?

断了今生、忘了曾经 提交于 2019-12-11 17:03:25
问题 I'd like to load a model automatically into a module by importing a module that loads the model and its constants into that module, somehow like this: In model.py : import pickle from tensorflow import keras def load_model_vars(): return pickle.load(open('./file.pkl', 'rb')) def load_model(): return keras.models.load_model('./model.h5') # model needs these two constants to be loaded successfully a, b = load_model_vars() model = load_model() In another.py , where model.py will be imported into

Tensorflow 2.0 Beta: Model.fit() throws ValueError: Arguments and signature arguments do not match: 56 57

老子叫甜甜 提交于 2019-12-11 14:55:10
问题 I'm new to machine learning. I'm trying to make a simple RNN in Tensorflow 2.0 but I'm hitting a snag. I've reduced it to a minimal example that reproduces the problem. The goal of this minimal example is for the RNN to learn to output 1.0 repeatedly. import os import sys import math from random import shuffle import numpy as np import tensorflow as tf from time import time as time epochs = 200 batch_size = 32 chunk_length = 64 features = 10 def main(): train_dataset = np.zeros([batch_size,

Access training operation in a tf.keras.Model

这一生的挚爱 提交于 2019-12-11 08:36:15
问题 How would one access a training operation from a tf.keras.models.Model ? Consider the following: import tensorflow as tf from tensorflow.keras.layers import Dense, Input, Flatten from tensorflow.keras.models import Model import numpy as np from sys import exit as xit # Make some dummy data dummy_data_shape=(5,5) def batch_generator(size): """ Makes some random data """ def _gen(): y_batch=np.random.randint(0,2, size=size) y_batch=np.expand_dims(y_batch,-1) y_expanded=np.expand_dims(y_batch,-1

tf.keras loss becomes NaN

喜夏-厌秋 提交于 2019-12-10 17:21:33
问题 I'm programming a neural network in tf.keras, with 3 layers. My dataset is the MNIST dataset. I decreased the number of examples in the dataset, so the runtime is lower. This is my code: import tensorflow as tf from tensorflow.keras import layers import numpy as np import pandas as pd !git clone https://github.com/DanorRon/data %cd data !ls batch_size = 32 epochs = 10 alpha = 0.0001 lambda_ = 0 h1 = 50 train = pd.read_csv('/content/first-repository/mnist_train.csv.zip') test = pd.read_csv('