rinuboney / ladder

Ladder network is a deep learning algorithm that combines supervised and unsupervised learning.
MIT License
242 stars 92 forks source link

Index out of range in ladder.py #12

Open samdogangs91 opened 7 years ago

samdogangs91 commented 7 years ago

Hello, I have the following issue when running your code:

"Traceback (most recent call last): File "/home/mblack/stage/ladder-master (1)/ladder.py", line 177, in u = tf.matmul(z_est[l+1], weights['V'][l]) IndexError: list index out of range"

Can you please tell me what's going wrong?

bsick commented 7 years ago

I had the same problem and could solve it by adapting to code from python 2.7 to python 3. Especially, it was necessary in the ladder.py code to replace line 34 shapes = zip(layer_sizes[:-1], layer_sizes[1:]) # shapes of linear layers by shapes = list(zip(list(layer_sizes)[:-1], list(layer_sizes[1:])))

also in the input_data.py I had to adapt the code for the data download to python 3:

SOURCE_URL = 'http://yann.lecun.com/exdb/mnist/' import urllib.request # adapt for python3

def maybe_download(filename, work_directory): """Download the data from Yann's website, unless it's already here.""" if not os.path.exists(work_directory): os.mkdir(work_directory) filepath = os.path.join(workdirectory, filename) if not os.path.exists(filepath): filepath, = urllib.request.urlretrieve(SOURCE_URL + filename, filepath) #adapt py3 statinfo = os.stat(filepath) print('Succesfully downloaded', filename, statinfo.st_size, 'bytes.') return filepath

samdogangs91 commented 7 years ago

Sorry for the late answer, thanks you! I have an other error now during runnig time: TypeError: Fetch argument 0.9983333333333333 has invalid type <class 'float'>, must be a string or Tensor. (Can not convert a float into a Tensor or Operation.)

ugurgudelek commented 7 years ago

In addition to bsick: In input_data.py line 153 "n_from_each_class = n_labeled // n_classes #py3 adapt" In ladder.py line 21 "num_iter = (num_examples//batch_size) num_epochs # number of loop iterations" In ladder.py line 233 "if (i > 1) and ((i+1) % (num_iter//num_epochs) == 0):" In ladder.py line 218 "i_iter = (epoch_n+1) (num_examples//batch_size)" In ladder.py line 234 epoch_n = i//(num_examples//batch_size) should be applied because of py2 py3 division difference.

In ladder.py line 243 should be changed "with with open('train_log', 'a') as train_log:" because of binary open difference between py2&3

pollenjp commented 6 years ago

@bsick commented on Mar 23, 2017

I had the same problem and could solve it by adapting to code from python 2.7 to python 3. Especially, it was necessary in the ladder.py code to replace line 34 shapes = zip(layer_sizes[:-1], layer_sizes[1:]) # shapes of linear layers by shapes = list(zip(list(layer_sizes)[:-1], list(layer_sizes[1:])))

also in the input_data.py I had to adapt the code for the data download to python 3:

SOURCE_URL = 'http://yann.lecun.com/exdb/mnist/' import urllib.request # adapt for python3

def maybe_download(filename, work_directory): """Download the data from Yann's website, unless it's already here.""" if not os.path.exists(work_directory): os.mkdir(work_directory) filepath = os.path.join(workdirectory, filename) if not os.path.exists(filepath): filepath, = urllib.request.urlretrieve(SOURCE_URL + filename, filepath) #adapt py3 statinfo = os.stat(filepath) print('Succesfully downloaded', filename, statinfo.st_size, 'bytes.') return filepath

SOURCE_URL = 'http://yann.lecun.com/exdb/mnist/'

def maybe_download(filename, work_directory):
    """
    Download the data from Yann's website, unless it's already here.
    """
    if not os.path.exists(work_directory):
        os.mkdir(work_directory)
    filepath = os.path.join(work_directory, filename)
    if not os.path.exists(filepath):
        filepath, _ = urllib.request.urlretrieve(SOURCE_URL + filename, filepath) #adapt py3
        statinfo = os.stat(filepath)
        print('Succesfully downloaded', filename, statinfo.st_size, 'bytes.')
    return filepath