In [1]:
import numpy as np
import h5py
import pickle
from time import time
import sys
import bhtsne

LOG_PATH = '/tmp/my_log.txt'
sys.stdout = open(LOG_PATH, 'w')
# sys.stderr = open(LOG_PATH, 'w')

FEAT_TRAIN = '/media/raid_arr/data/ndsb/features/features_train.hdf5'
# FEAT_TRAIN = '~/data/ndsb/features/features_train.hdf5'
FEAT_TEST = '/media/raid_arr/data/ndsb/features/features_test.hdf5'

LAYER = 'fc2'
MODE = ['train', 'predict']

In [2]:
# f_train.close()
f_train = h5py.File(FEAT_TRAIN, 'r')
f_test = h5py.File(FEAT_TEST, 'r')

In [3]:
train_feats_db = f_train[LAYER]
train_lbls_db = f_train['lbls']

test_feats_db = f_test[LAYER]
test_lbls_db = f_test['lbls']
test_paths_db = f_test['im_paths']

train_feats = train_feats_db[()]
test_feats = test_feats_db[()]
train_lbls = train_lbls_db[()]
test_lbls = test_lbls_db[()]

In [4]:
SAVE_PATH = '/media/raid_arr/data/ndsb/tsne2.p'
tsne = bhtsne.bh_tsne(np.r_[train_feats, test_feats], verbose=True)

tic = time()
x2 = np.array([r for r in tsne])
toc = time() - tic
print toc
pickle.dump(x2, open(SAVE_PATH, 'wb'))


---------------------------------------------------------------------------
UnsupportedOperation                      Traceback (most recent call last)
<ipython-input-4-3cf694d8e3f7> in <module>()
      4 
      5 tic = time()
----> 6 x2 = np.array([r for r in tsne])
      7 toc = time() - tic
      8 print toc

/usr/local/bin/bhtsne.py in bh_tsne(samples, no_dims, perplexity, theta, randseed, verbose)
    115                     # bh_tsne is very noisy on stdout, tell it to use stderr
    116                     #   if it is to print any output
--> 117                     stdout=stderr if verbose else dev_null)
    118             bh_tsne_p.wait()
    119             assert not bh_tsne_p.returncode, ('ERROR: Call to bh_tsne exited '

/usr/lib/python2.7/subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
    700         (p2cread, p2cwrite,
    701          c2pread, c2pwrite,
--> 702          errread, errwrite), to_close = self._get_handles(stdin, stdout, stderr)
    703 
    704         try:

/usr/lib/python2.7/subprocess.pyc in _get_handles(self, stdin, stdout, stderr)
   1126             else:
   1127                 # Assuming file-like object
-> 1128                 c2pwrite = stdout.fileno()
   1129 
   1130             if stderr is None:

/usr/lib/python2.7/site-packages/IPython/kernel/zmq/iostream.py in fileno(self)
    192 
    193     def fileno(self):
--> 194         raise UnsupportedOperation("IOStream has no fileno.")
    195 
    196     def write(self, string):

UnsupportedOperation: IOStream has no fileno.