tffm icon indicating copy to clipboard operation
tffm copied to clipboard

Issue with tensorflow 2.0: module 'tensorflow_core._api.v2.train' has no attribute 'AdamOptimizer'

Open hugocool opened this issue 4 years ago • 2 comments

pip install tensorflow==2.0 import numpy as np import tensorflow as tf

from tffm import TFFMClassifier

gives error:

AttributeError Traceback (most recent call last) in ----> 1 from tffm import TFFMClassifier

~/anaconda3/lib/python3.7/site-packages/tffm/init.py in ----> 1 from .models import TFFMClassifier, TFFMRegressor 2 3 all = ['TFFMClassifier', 'TFFMRegressor']

~/anaconda3/lib/python3.7/site-packages/tffm/models.py in 2 3 import numpy as np ----> 4 from .base import TFFMBaseModel 5 from .utils import loss_logistic, loss_mse, sigmoid 6

~/anaconda3/lib/python3.7/site-packages/tffm/base.py in 1 import tensorflow as tf ----> 2 from .core import TFFMCore 3 from sklearn.base import BaseEstimator 4 from abc import ABCMeta, abstractmethod 5 import six

~/anaconda3/lib/python3.7/site-packages/tffm/core.py in 4 5 ----> 6 class TFFMCore(): 7 """This class implements underlying routines about creating computational graph. 8

~/anaconda3/lib/python3.7/site-packages/tffm/core.py in TFFMCore() 94 """ 95 def init(self, order=2, rank=2, input_type='dense', loss_function=None, ---> 96 optimizer=tf.train.AdamOptimizer(learning_rate=0.01), reg=0, 97 init_std=0.01, use_diag=False, reweight_reg=False, 98 seed=None):

AttributeError: module 'tensorflow_core._api.v2.train' has no attribute 'AdamOptimizer'

hugocool avatar Dec 29 '19 18:12 hugocool

FIX: Go to core.py file inside ttf folder. In the in the init function change optimizer to tf.keras.optimizers.Adam(....). Why? Read the following: https://stackoverflow.com/questions/55682718/module-tensorflow-api-v2-train-has-no-attribute-gradientdescentoptimizer

Pager07 avatar Mar 10 '20 00:03 Pager07

I ported this to tf2, check it out here: https://github.com/jamborta/tffm2

jamborta avatar Jun 08 '20 12:06 jamborta