Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for keras layer DenseFeatures #2443

Closed
blidblid opened this issue Nov 27, 2019 · 10 comments
Closed

Add support for keras layer DenseFeatures #2443

blidblid opened this issue Nov 27, 2019 · 10 comments

Comments

@blidblid
Copy link

TensorFlow.js version

1.3.2

Browser version

Chome 78.0.3904.108

Describe the feature request

Add support for the keras layer DenseFeatures.

Code to reproduce the bug / link to feature request

Step 1:

Create a model in Python using the DenseFeatures layer.

       feature_columns = [tf.feature_column.numeric_column('foo')]
       feature_layer = tf.keras.layers.DenseFeatures(feature_columns)
       model = tf.keras.Sequential([
            feature_layer,
            tf.keras.layers.Dense(8),
            tf.keras.layers.Dense(1)
      ])
Step 2:

Train, fit and then save the model using tfjs.converters.save_keras_model(model, 'path_to_model')

Step 3:

Load the model into tfjs: tf.loadLayersModel('./model.json');
It will throw: Error: Uncaught (in promise): Error: Unknown layer: DenseFeatures.

@rthadur rthadur added comp:layers type:feature New feature or request labels Nov 28, 2019
@caisq caisq added the P3 label Nov 28, 2019
@blidblid
Copy link
Author

Will this be part of any upcoming tfjs release?

@tafsiri
Copy link
Contributor

tafsiri commented Jan 15, 2020

@caisq I don't think anyone is actively working on this. Mind if I add a contributions welcome tag here?

@caisq
Copy link
Collaborator

caisq commented Jan 15, 2020

@tafsiri Please go ahead.

@blidblid
Copy link
Author

blidblid commented Feb 3, 2020

For any interested, a workaround is to freeze the model. That way you can use DenseFeatures and give predictions in tfjs:

model.save(temp_path, overwrite=True)
tfjs.converters.convert_tf_saved_model(temp_path, path)

and then

const model = await tf.loadGraphModel(path);

@djemeljanovs
Copy link

@blidblid, For some reasons suggested workaround does not apply for my model with the error:
AssertionError: Identity is not in graph

Meanwhile I have started porting DenseFeatures layer to tfjs in this branch:
https://github.com/djemeljanovs/tfjs/tree/feature/dense-feature-layer-support

It seems to be excessive amount of work, since not only DenseFeatures, but whole FeatureColumn API has not been ported to tfjs yet.

@tafsiri, I tried to create branch for this on tfjs, but git did not allow me that, so I created a fork. Could you please check out if this is not the right place to do, I am quite new to contributions. Thank you!

@inguelberth
Copy link

For any interested, a workaround is to freeze the model. That way you can use DenseFeatures and give predictions in tfjs:

model.save(temp_path, overwrite=True)
tfjs.converters.convert_tf_saved_model(temp_path, path)

and then

const model = await tf.loadGraphModel(path);

hey @blidblid in which version of tensorflow have you tested this trick?

@blidblid
Copy link
Author

blidblid commented Oct 8, 2020

Python                   3.7.5
tensorflow               2.3.0
tensorflowjs             1.5.2

Not all feature columns seem to work with this method. I had to use categorical_column_with_identity over categorical_column_with_vocabulary_list.

@gaikwadrahul8
Copy link
Contributor

Hi, @blidblid

Apologize for the delayed response and It seems like we haven't implemented this feature request for DenseFeatures Op as of now and May I know still are you looking for this DenseFeatures Op ?

If someone wants to contribute for DenseFeatures Op, you're always welcome and please feel free to do it and refer this link. Thank you!

@google-ml-butler
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you.

@google-ml-butler
Copy link

Closing as stale. Please @mention us if this needs more attention.

@gaikwadrahul8 gaikwadrahul8 self-assigned this May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants