def stack(net, level): n = pu.copy_net_params(net) enc_prev = None dec_prev = None enc = None dec = None for l in n.layer: if l.name.lower().endswith('encode%03dneuron' % (level-1)): enc = pu.copy_msg(l, LayerParameter) for b in list(enc.bottom): l.bottom.remove(b) for t in list(l.top): l.bottom.append(unicode(t)) # preserve order of layer bottoms, label as bottom has to come last elif l.name.lower().endswith('decode%03dneuron' % (level-1)): dec_prev = l dec = pu.copy_msg(l, LayerParameter) enc.name = 'encode%03dneuron' % level dec.name = 'encode%03dneuron' % level return n
def test_copy_net_params(self): fpath = os.path.join(os.path.dirname(ROOT_PKG_PATH), TEST_DATA_DIRNAME, TEST_NET_FILENAME) parser = pu.Parser() x = parser.from_net_params_file(fpath) y = pu.copy_net_params(x) assert_is_not(x, y, "References to the same instance.") assert_is_not_none(y) assert_equal(text_format.MessageToString(x), text_format.MessageToString(y))