Python theano.compat() Examples
The following are 2
code examples of theano.compat().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
theano
, or try the search function
.
Example #1
Source File: test_function_module.py From D-VAE with MIT License | 5 votes |
def test_broken_pickle_with_shared(self): saves = [] def pers_save(obj): if isinstance(obj, numpy.ndarray): saves.append(obj) return len(saves) - 1 else: return None def pers_load(id): return saves[id] b = numpy.random.rand(5, 4) x = theano.tensor.matrix() y = theano.shared(b) f = theano.function([x], theano.tensor.dot(x, y)) from theano.compat import BytesIO fp = BytesIO() p = pickle.Pickler(fp, 2) p.persistent_id = pers_save try: p.dump(f) except NotImplementedError as e: if exc_message(e).startswith('DebugMode is not picklable'): return else: raise fp2 = BytesIO(fp.getvalue()) fp.close() p = pickle.Unpickler(fp2) p.persistent_load = pers_load p.load() fp2.close()
Example #2
Source File: test_function_module.py From attention-lvcsr with MIT License | 5 votes |
def test_broken_pickle_with_shared(self): saves = [] def pers_save(obj): if isinstance(obj, numpy.ndarray): saves.append(obj) return len(saves)-1 else: return None def pers_load(id): return saves[id] a = numpy.random.rand(4, 5) b = numpy.random.rand(5, 4) x = theano.tensor.matrix() y = theano.shared(b) f = theano.function([x], theano.tensor.dot(x, y)) from theano.compat import BytesIO fp = BytesIO() p = pickle.Pickler(fp, 2) p.persistent_id = pers_save try: p.dump(f) except NotImplementedError as e: if exc_message(e).startswith('DebugMode is not picklable'): return else: raise fp2 = BytesIO(fp.getvalue()) fp.close() p = pickle.Unpickler(fp2) p.persistent_load = pers_load f2 = p.load() fp2.close()