albertbup / deep-belief-network

A Python implementation of Deep Belief Networks built upon NumPy and TensorFlow with scikit-learn compatibility
MIT License
481 stars 212 forks source link

Update to Tensorflow 2 #46

Open cossio opened 4 years ago

cossio commented 4 years ago

On Tensorflow 2 I get some errors, e.g.:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-2516a398efe0> in <module>
----> 1 from dbn.tensorflow import SupervisedDBNClassification
      2 import numpy as np
      3 import pandas as pd
      4 from sklearn.model_selection import train_test_split
      5 from sklearn.metrics.classification import accuracy_score

~/RBMpro/jupyter/tf-dbn/dbn/tensorflow/__init__.py in <module>
----> 1 from .models import BinaryRBM, UnsupervisedDBN, SupervisedDBNRegression, SupervisedDBNClassification

~/RBMpro/jupyter/tf-dbn/dbn/tensorflow/models.py in <module>
     17 
     18 
---> 19 sess = tf.Session()
     20 atexit.register(close_session)
     21 

AttributeError: module 'tensorflow' has no attribute 'Session'

Please update

bhurghundii commented 4 years ago

Hello, this is the fix I have used: I went into the models.py and added this line to the end of the imports:

import tensorflow.compat.v1 as tf tf.disable_v2_behavior()

This should switch you back to v1.x behaviour. This is a temporary placeholder. I'll fork this sometime and write it for 2.x

USTBVEO commented 3 years ago

Hello, I suggest using the code as follows:

import tensorflow._api.v2.compat.v1 as tf tf.disable_v2_behavior()