models icon indicating copy to clipboard operation
models copied to clipboard

how to use tf.feature_column with tf.keras.Model

Open wendongqu opened this issue 7 years ago • 5 comments

Please go to Stack Overflow for help and support:

http://stackoverflow.com/questions/tagged/tensorflow

Also, please understand that many of the models included in this repository are experimental and research-style code. If you open a GitHub issue, here is our policy:

  1. It must be a bug, a feature request, or a significant problem with documentation (for small docs fixes please send a PR instead).
  2. The form below must be filled out.

Here's why we have that policy: TensorFlow developers respond to issues. We want to focus on work that benefits the whole community, e.g., fixing bugs and adding features. Support only helps individuals. GitHub also notifies thousands of people when issues are filed. We want them to see you communicating an interesting problem, rather than being redirected to Stack Overflow.


System information

  • What is the top-level directory of the model you are using:
  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow):
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04):
  • TensorFlow installed from (source or binary):
  • TensorFlow version (use command below):
  • Bazel version (if compiling from source):
  • CUDA/cuDNN version:
  • GPU model and memory:
  • Exact command to reproduce:

You can collect some of this information using our environment capture script:

https://github.com/tensorflow/tensorflow/tree/master/tools/tf_env_collect.sh

You can obtain the TensorFlow version with

python -c "import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)"

Describe the problem

Describe the problem clearly here. Be sure to convey here why it's a bug in TensorFlow or a feature request.

Source code / logs

Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached. Try to provide a reproducible test case that is the bare minimum necessary to generate the problem.

wendongqu avatar Apr 17 '19 23:04 wendongqu

there is a nice example in https://www.tensorflow.org/alpha/tutorials/keras/feature_columns on how to use tf.feature_column with tf.keras. But that model is using Sequential

model = tf.keras.Sequential([ feature_layer, layers.Dense(128, activation='relu'), layers.Dense(128, activation='relu'), layers.Dense(1, activation='sigmoid') ])

model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])

model.fit(train_ds, validation_data=val_ds, epochs=5)

How would you do it with tf.kears.Model? Ideally, I would like to have

ipt=tf.keras.layers.Input(?? not sure what I should put in here if I want to use densefeature next?) x=tf.keras.layers.DenseFeatures(feature_columns)(ipt) x=tf.keras.layers.Dense(1)(x)

model=tf.kears.Model(input=ipt, output=x)

How can you make this work?

thank you!

wendongqu avatar Apr 18 '19 00:04 wendongqu

there is a nice example in https://www.tensorflow.org/alpha/tutorials/keras/feature_columns on how to use tf.feature_column with tf.keras. But that model is using Sequential

model = tf.keras.Sequential([ feature_layer, layers.Dense(128, activation='relu'), layers.Dense(128, activation='relu'), layers.Dense(1, activation='sigmoid') ])

model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])

model.fit(train_ds, validation_data=val_ds, epochs=5)

How would you do it with tf.kears.Model? Ideally, I would like to have

ipt=tf.keras.layers.Input(?? not sure what I should put in here if I want to use densefeature next?) x=tf.keras.layers.DenseFeatures(feature_columns)(ipt) x=tf.keras.layers.Dense(1)(x)

model=tf.kears.Model(input=ipt, output=x)

How can you make this work?

thank you!

Do u figure out how to get this work? thx

littlebeandog avatar Oct 09 '19 07:10 littlebeandog

Feature Columns and the keras functional API https://blog.csdn.net/n1007530194/article/details/104043984

farfun avatar Jan 19 '20 10:01 farfun

@wendongqu

Is this still an issue.Please, close this thread if your issue was resolved. Thanks!

ravikyram avatar Jul 01 '20 09:07 ravikyram

Automatically closing due to lack of recent activity. Please update the issue when new information becomes available, and we will reopen the issue. Thanks!

ravikyram avatar Aug 08 '20 02:08 ravikyram