Open38

古い Keras の環境 (Python3.5) でエクスポートされた .h5 に含まれている Lambda ファンクションをデコード

PINTOPINTO

https://github.com/yu-li/AGLLNet

    model = load_model('model/AgLLNet.h5')

    model.summary()

    def get_layer(model, layer_name, not_found=None):
        for i, l in enumerate(model.layers):
            if l.name == layer_name:
                return i, l
        return not_found

    # https://github.com/keras-team/keras/issues/2582
    idx, layer = get_layer(model, 'lambda_1')
    print(layer.get_config())
{
    'dtype': 'float32',
    'output_shape_type': 'raw',
    'output_shape_module': None,
    'function': ('4wEAAAAAAAAAAwAAAAcAAABTAAAAc2wAAABkAQB8AABkAABkAACFAgBkAABkAACFAgBkAABkAACF\nAgBkAABkAQCFAgBmBAAZGGQCABd9AQB8AABkAABkAACFAgBkAABkAACFAgBkAABkAACFAgBkAQBk\nAwCFAgBmBAAZfQIAfAIAfAEAG1MpBE7pAQAAAGfxaOOItfjkPukEAAAAqQApA9oBeFoEaWxsddoD\naW1ncgMAAAByAwAAAPopL2hvbWUvbGZmL1RJUC8yMDE5MDkxNF9yZXRpbmV4L05ldHdvcmsucHna\nC3JldGluZXhfY2F1mAAAAHMGAAAAAAE2AS4B\n', None, None),
    'name': 'lambda_1',
    'function_type': 'lambda',
    'module': 'tensorflow.python.keras.layers.core',
    'output_shape': None,
    'trainable': True,
    'arguments': {}
}

PINTOPINTO
    # https://github.com/keras-team/keras/issues/2582
    idx, layer = get_layer(model, 'lambda_1')
    print(layer.get_config()['function'][0])
    import base64
    data = base64.b64decode(layer.get_config()['function'][0])
    print(data)
b'\xe3\x01\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x07\x00\x00\x00S\x00\x00\x00sl\x00\x00\x00d\x01\x00|\x00\x00d\x00\x00d\x00\x00\x85\x02\x00d\x00\x00d\x00\x00\x85\x02\x00d\x00\x00d\x00\x00\x85\x02\x00d\x00\x00d\x01\x00\x85\x02\x00f\x04\x00\x19\x18d\x02\x00\x17}\x01\x00|\x00\x00d\x00\x00d\x00\x00\x85\x02\x00d\x00\x00d\x00\x00\x85\x02\x00d\x00\x00d\x00\x00\x85\x02\x00d\x01\x00d\x03\x00\x85\x02\x00f\x04\x00\x19}\x02\x00|\x02\x00|\x01\x00\x1bS)\x04N\xe9\x01\x00\x00\x00g\xf1h\xe3\x88\xb5\xf8\xe4>\xe9\x04\x00\x00\x00\xa9\x00)\x03\xda\x01xZ\x04illu\xda\x03imgr\x03\x00\x00\x00r\x03\x00\x00\x00\xfa)/home/lff/TIP/20190914_retinex/Network.py\xda\x0bretinex_cau\x98\x00\x00\x00s\x06\x00\x00\x00\x00\x016\x01.\x01'
PINTOPINTO
$ cd __pycache__
$ ls -l 
total 4
-rw-rw-r-- 1 b920405 b920405 210 1114 14:52 test.cpython-38.pyc

$ uncompyle6 test.cpython-38.pyc

# uncompyle6 version 3.8.0
# Python bytecode 3.8.0 (3413)
# Decompiled from: Python 3.8.10 (default, Sep 28 2021, 16:10:42) 
# [GCC 9.3.0]
# Embedded file name: test.py
# Compiled at: 2021-11-14 14:51:46
# Size of source mod 2**32: 47 bytes

def test_func(a, b):
    a = a + b
    return a
# okay decompiling test.cpython-38.pyc
PINTOPINTO

Python3.5 Environment

function_serial_to_byte_to_binaryfile.py

f = open('mytest.pyc', 'wb')
f.write(b'4wEAAAAAAAAAAwAAAAcAAABTAAAAc2wAAABkAQB8AABkAABkAACFAgBkAABkAACFAgBkAABkAACF\nAgBkAABkAQCFAgBmBAAZGGQCABd9AQB8AABkAABkAACFAgBkAABkAACFAgBkAABkAACFAgBkAQBk\nAwCFAgBmBAAZfQIAfAIAfAEAG1MpBE7pAQAAAGfxaOOItfjkPukEAAAAqQApA9oBeFoEaWxsddoD\naW1ncgMAAAByAwAAAPopL2hvbWUvbGZmL1RJUC8yMDE5MDkxNF9yZXRpbmV4L05ldHdvcmsucHna\nC3JldGluZXhfY2F1mAAAAHMGAAAAAAE2AS4B\n')
f.close()
PINTOPINTO
$ docker run --rm -it --gpus all \
-v ${PWD}:/work \
pinto0309/whenet
PINTOPINTO
# cd /work
# ls -l
total 12
drwxrwxr-x 2 1000 1000 4096 Nov 14 05:52 __pycache__
-rw-rw-r-- 1 1000 1000  401 Nov 14 06:09 function_serial_to_byte_to_binaryfile.py
-rw-rw-r-- 1 1000 1000   47 Nov 14 05:51 test.py
PINTOPINTO
import marshal
function = marshal.dumps(b'4wEAAAAAAAAAAwAAAAcAAABTAAAAc2wAAABkAQB8AABkAABkAACFAgBkAABkAACFAgBkAABkAACF\nAgBkAABkAQCFAgBmBAAZGGQCABd9AQB8AABkAABkAACFAgBkAABkAACFAgBkAABkAACFAgBkAQBk\nAwCFAgBmBAAZfQIAfAIAfAEAG1MpBE7pAQAAAGfxaOOItfjkPukEAAAAqQApA9oBeFoEaWxsddoD\naW1ncgMAAAByAwAAAPopL2hvbWUvbGZmL1RJUC8yMDE5MDkxNF9yZXRpbmV4L05ldHdvcmsucHna\nC3JldGluZXhfY2F1mAAAAHMGAAAAAAE2AS4B\n').decode('raw_unicode_escape')

f = open('mytest.pyc', 'wb')
f.write(function)
f.close()
PINTOPINTO
import codecs
import marshal
import inspect

code = '4wEAAAAAAAAAAwAAAAcAAABTAAAAc2wAAABkAQB8AABkAABkAACFAgBkAABkAACFAgBkAABkAACF\nAgBkAABkAQCFAgBmBAAZGGQCABd9AQB8AABkAABkAACFAgBkAABkAACFAgBkAABkAACFAgBkAQBk\nAwCFAgBmBAAZfQIAfAIAfAEAG1MpBE7pAQAAAGfxaOOItfjkPukEAAAAqQApA9oBeFoEaWxsddoD\naW1ncgMAAAByAwAAAPopL2hvbWUvbGZmL1RJUC8yMDE5MDkxNF9yZXRpbmV4L05ldHdvcmsucHna\nC3JldGluZXhfY2F1mAAAAHMGAAAAAAE2AS4B\n'
raw_code = codecs.decode(code.encode('ascii'), 'base64')
decoded_code = marshal.loads(raw_code)
inspect.getmembers(decoded_code)
PINTOPINTO
[('__class__', <class 'code'>), ('__delattr__', <method-wrapper '__delattr__' of code object at 0x7f976c468e40>), ('__dir__', <built-in method __dir__ of code object at 0x7f976c468e40>), ('__doc__', 'code(argcount, kwonlyargcount, nlocals, stacksize, flags, codestring,\n      constants, names, varnames, filename, name, firstlineno,\n      lnotab[, freevars[, cellvars]])\n\nCreate a code object.  Not for the faint of heart.'), ('__eq__', <method-wrapper '__eq__' of code object at 0x7f976c468e40>), ('__format__', <built-in method __format__ of code object at 0x7f976c468e40>), ('__ge__', <method-wrapper '__ge__' of code object at 0x7f976c468e40>), ('__getattribute__', <method-wrapper '__getattribute__' of code object at 0x7f976c468e40>), ('__gt__', <method-wrapper '__gt__' of code object at 0x7f976c468e40>), ('__hash__', <method-wrapper '__hash__' of code object at 0x7f976c468e40>), ('__init__', <method-wrapper '__init__' of code object at 0x7f976c468e40>), ('__le__', <method-wrapper '__le__' of code object at 0x7f976c468e40>), ('__lt__', <method-wrapper '__lt__' of code object at 0x7f976c468e40>), ('__ne__', <method-wrapper '__ne__' of code object at 0x7f976c468e40>), ('__new__', <built-in method __new__ of type object at 0xa36ec0>), ('__reduce__', <built-in method __reduce__ of code object at 0x7f976c468e40>), ('__reduce_ex__', <built-in method __reduce_ex__ of code object at 0x7f976c468e40>), ('__repr__', <method-wrapper '__repr__' of code object at 0x7f976c468e40>), ('__setattr__', <method-wrapper '__setattr__' of code object at 0x7f976c468e40>), ('__sizeof__', <built-in method __sizeof__ of code object at 0x7f976c468e40>), ('__str__', <method-wrapper '__str__' of code object at 0x7f976c468e40>), ('__subclasshook__', <built-in method __subclasshook__ of type object at 0xa36ec0>), ('co_argcount', 1), ('co_cellvars', ()), ('co_code', b'd\x01\x00|\x00\x00d\x00\x00d\x00\x00\x85\x02\x00d\x00\x00d\x00\x00\x85\x02\x00d\x00\x00d\x00\x00\x85\x02\x00d\x00\x00d\x01\x00\x85\x02\x00f\x04\x00\x19\x18d\x02\x00\x17}\x01\x00|\x00\x00d\x00\x00d\x00\x00\x85\x02\x00d\x00\x00d\x00\x00\x85\x02\x00d\x00\x00d\x00\x00\x85\x02\x00d\x01\x00d\x03\x00\x85\x02\x00f\x04\x00\x19}\x02\x00|\x02\x00|\x01\x00\x1bS'), ('co_consts', (None, 1, 1e-05, 4)), ('co_filename', '/home/lff/TIP/20190914_retinex/Network.py'), ('co_firstlineno', 152), ('co_flags', 83), ('co_freevars', ()), ('co_kwonlyargcount', 0), ('co_lnotab', b'\x00\x016\x01.\x01'), ('co_name', 'retinex_cau'), ('co_names', ()), ('co_nlocals', 3), ('co_stacksize', 7), ('co_varnames', ('x', 'illu', 'img'))]
PINTOPINTO
[
    ('__class__', <class 'code'>),
    ('__delattr__', <method-wrapper '__delattr__' of code object at 0x7f976c468e40>),
    ('__dir__', <built-in method __dir__ of code object at 0x7f976c468e40>),
    ('__doc__', 'code(argcount, kwonlyargcount, nlocals, stacksize, flags, codestring, constants, names, varnames, filename, name, firstlineno, lnotab[, freevars[, cellvars]]) Create a code object.  Not for the faint of heart.'),
    ('__eq__', <method-wrapper '__eq__' of code object at 0x7f976c468e40>),
    ('__format__', <built-in method __format__ of code object at 0x7f976c468e40>),
    ('__ge__', <method-wrapper '__ge__' of code object at 0x7f976c468e40>),
    ('__getattribute__', <method-wrapper '__getattribute__' of code object at 0x7f976c468e40>),
    ('__gt__', <method-wrapper '__gt__' of code object at 0x7f976c468e40>),
    ('__hash__', <method-wrapper '__hash__' of code object at 0x7f976c468e40>),
    ('__init__', <method-wrapper '__init__' of code object at 0x7f976c468e40>),
    ('__le__', <method-wrapper '__le__' of code object at 0x7f976c468e40>),
    ('__lt__', <method-wrapper '__lt__' of code object at 0x7f976c468e40>),
    ('__ne__', <method-wrapper '__ne__' of code object at 0x7f976c468e40>),
    ('__new__', <built-in method __new__ of type object at 0xa36ec0>),
    ('__reduce__', <built-in method __reduce__ of code object at 0x7f976c468e40>),
    ('__reduce_ex__', <built-in method __reduce_ex__ of code object at 0x7f976c468e40>),
    ('__repr__', <method-wrapper '__repr__' of code object at 0x7f976c468e40>),
    ('__setattr__', <method-wrapper '__setattr__' of code object at 0x7f976c468e40>),
    ('__sizeof__', <built-in method __sizeof__ of code object at 0x7f976c468e40>),
    ('__str__', <method-wrapper '__str__' of code object at 0x7f976c468e40>),
    ('__subclasshook__', <built-in method __subclasshook__ of type object at 0xa36ec0>),
    ('co_argcount', 1),
    ('co_cellvars', ()),
    ('co_code', b'd\x01\x00|\x00\x00d\x00\x00d\x00\x00\x85\x02\x00d\x00\x00d\x00\x00\x85\x02\x00d\x00\x00d\x00\x00\x85\x02\x00d\x00\x00d\x01\x00\x85\x02\x00f\x04\x00\x19\x18d\x02\x00\x17}\x01\x00|\x00\x00d\x00\x00d\x00\x00\x85\x02\x00d\x00\x00d\x00\x00\x85\x02\x00d\x00\x00d\x00\x00\x85\x02\x00d\x01\x00d\x03\x00\x85\x02\x00f\x04\x00\x19}\x02\x00|\x02\x00|\x01\x00\x1bS'),
    ('co_consts', (None, 1, 1e-05, 4)),
    ('co_filename', '/home/lff/TIP/20190914_retinex/Network.py'),
    ('co_firstlineno', 152),
    ('co_flags', 83),
    ('co_freevars', ()),
    ('co_kwonlyargcount', 0),
    ('co_lnotab', b'\x00\x016\x01.\x01'),
    ('co_name', 'retinex_cau'),
    ('co_names', ()),
    ('co_nlocals', 3),
    ('co_stacksize', 7),
    ('co_varnames', ('x', 'illu', 'img'))
]
PINTOPINTO
code =b'd\x01\x00|\x00\x00d\x00\x00d\x00\x00\ufffd\x02\x00d\x00\x00d\x00\x00\ufffd\x02\x00d\x00\x00d\x00\x00\ufffd\x02\x00d\x00\x00d\x01\x00\ufffd\x02\x00f\x04\x00\x19\x18d\x02\x00\x17}\x01\x00|\x00\x00d\x00\x00d\x00\x00\ufffd\x02\x00d\x00\x00d\x00\x00\ufffd\x02\x00d\x00\x00d\x00\x00\ufffd\x02\x00d\x01\x00d\x03\x00\ufffd\x02\x00f\x04\x00\x19}\x02\x00|\x02\x00|\x01\x00\x1bS'

inspect.getmembers(code)
PINTOPINTO
[
    ('__add__', <method-wrapper '__add__' of bytes object at 0x7f976c49c5f0>),
    ('__class__', <class 'bytes'>),
    ('__contains__', <method-wrapper '__contains__' of bytes object at 0x7f976c49c5f0>),
    ('__delattr__', <method-wrapper '__delattr__' of bytes object at 0x7f976c49c5f0>),
    ('__dir__', <built-in method __dir__ of bytes object at 0x7f976c49c5f0>),
    ('__doc__', 'bytes(iterable_of_ints) -> bytes\nbytes(string, encoding[, errors]) -> bytes\nbytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer\nbytes(int) -> bytes object of size given by the parameter initialized with null bytes\nbytes() -> empty bytes object\n\nConstruct an immutable array of bytes from:\n  - an iterable yielding integers in range(256)\n  - a text string encoded using the specified encoding\n  - any object implementing the buffer API.\n  - an integer'),
    ('__eq__', <method-wrapper '__eq__' of bytes object at 0x7f976c49c5f0>),
    ('__format__', <built-in method __format__ of bytes object at 0x7f976c49c5f0>),
    ('__ge__', <method-wrapper '__ge__' of bytes object at 0x7f976c49c5f0>),
    ('__getattribute__', <method-wrapper '__getattribute__' of bytes object at 0x7f976c49c5f0>),
    ('__getitem__', <method-wrapper '__getitem__' of bytes object at 0x7f976c49c5f0>),
    ('__getnewargs__', <built-in method __getnewargs__ of bytes object at 0x7f976c49c5f0>),
    ('__gt__', <method-wrapper '__gt__' of bytes object at 0x7f976c49c5f0>),
    ('__hash__', <method-wrapper '__hash__' of bytes object at 0x7f976c49c5f0>),
    ('__init__', <method-wrapper '__init__' of bytes object at 0x7f976c49c5f0>),
    ('__iter__', <method-wrapper '__iter__' of bytes object at 0x7f976c49c5f0>),
    ('__le__', <method-wrapper '__le__' of bytes object at 0x7f976c49c5f0>),
    ('__len__', <method-wrapper '__len__' of bytes object at 0x7f976c49c5f0>),
    ('__lt__', <method-wrapper '__lt__' of bytes object at 0x7f976c49c5f0>),
    ('__mod__', <method-wrapper '__mod__' of bytes object at 0x7f976c49c5f0>),
    ('__mul__', <method-wrapper '__mul__' of bytes object at 0x7f976c49c5f0>),
    ('__ne__', <method-wrapper '__ne__' of bytes object at 0x7f976c49c5f0>),
    ('__new__', <built-in method __new__ of type object at 0xa3bd40>),
    ('__reduce__', <built-in method __reduce__ of bytes object at 0x7f976c49c5f0>),
    ('__reduce_ex__', <built-in method __reduce_ex__ of bytes object at 0x7f976c49c5f0>),
    ('__repr__', <method-wrapper '__repr__' of bytes object at 0x7f976c49c5f0>),
    ('__rmod__', <method-wrapper '__rmod__' of bytes object at 0x7f976c49c5f0>),
    ('__rmul__', <method-wrapper '__rmul__' of bytes object at 0x7f976c49c5f0>),
    ('__setattr__', <method-wrapper '__setattr__' of bytes object at 0x7f976c49c5f0>),
    ('__sizeof__', <built-in method __sizeof__ of bytes object at 0x7f976c49c5f0>),
    ('__str__', <method-wrapper '__str__' of bytes object at 0x7f976c49c5f0>),
    ('__subclasshook__', <built-in method __subclasshook__ of type object at 0xa3bd40>),
    ('capitalize', <built-in method capitalize of bytes object at 0x7f976c49c5f0>),
    ('center', <built-in method center of bytes object at 0x7f976c49c5f0>),
    ('count', <built-in method count of bytes object at 0x7f976c49c5f0>),
    ('decode', <built-in method decode of bytes object at 0x7f976c49c5f0>),
    ('endswith', <built-in method endswith of bytes object at 0x7f976c49c5f0>),
    ('expandtabs', <built-in method expandtabs of bytes object at 0x7f976c49c5f0>),
    ('find', <built-in method find of bytes object at 0x7f976c49c5f0>),
    ('fromhex', <built-in method fromhex of type object at 0xa3bd40>),
    ('hex', <built-in method hex of bytes object at 0x7f976c49c5f0>),
    ('index', <built-in method index of bytes object at 0x7f976c49c5f0>),
    ('isalnum', <built-in method isalnum of bytes object at 0x7f976c49c5f0>),
    ('isalpha', <built-in method isalpha of bytes object at 0x7f976c49c5f0>),
    ('isdigit', <built-in method isdigit of bytes object at 0x7f976c49c5f0>),
    ('islower', <built-in method islower of bytes object at 0x7f976c49c5f0>),
    ('isspace', <built-in method isspace of bytes object at 0x7f976c49c5f0>),
    ('istitle', <built-in method istitle of bytes object at 0x7f976c49c5f0>),
    ('isupper', <built-in method isupper of bytes object at 0x7f976c49c5f0>),
    ('join', <built-in method join of bytes object at 0x7f976c49c5f0>),
    ('ljust', <built-in method ljust of bytes object at 0x7f976c49c5f0>),
    ('lower', <built-in method lower of bytes object at 0x7f976c49c5f0>),
    ('lstrip', <built-in method lstrip of bytes object at 0x7f976c49c5f0>),
    ('maketrans', <built-in method maketrans of type object at 0xa3bd40>),
    ('partition', <built-in method partition of bytes object at 0x7f976c49c5f0>),
    ('replace', <built-in method replace of bytes object at 0x7f976c49c5f0>),
    ('rfind', <built-in method rfind of bytes object at 0x7f976c49c5f0>),
    ('rindex', <built-in method rindex of bytes object at 0x7f976c49c5f0>),
    ('rjust', <built-in method rjust of bytes object at 0x7f976c49c5f0>),
    ('rpartition', <built-in method rpartition of bytes object at 0x7f976c49c5f0>),
    ('rsplit', <built-in method rsplit of bytes object at 0x7f976c49c5f0>),
    ('rstrip', <built-in method rstrip of bytes object at 0x7f976c49c5f0>),
    ('split', <built-in method split of bytes object at 0x7f976c49c5f0>),
    ('splitlines', <built-in method splitlines of bytes object at 0x7f976c49c5f0>),
    ('startswith', <built-in method startswith of bytes object at 0x7f976c49c5f0>),
    ('strip', <built-in method strip of bytes object at 0x7f976c49c5f0>),
    ('swapcase', <built-in method swapcase of bytes object at 0x7f976c49c5f0>),
    ('title', <built-in method title of bytes object at 0x7f976c49c5f0>),
    ('translate', <built-in method translate of bytes object at 0x7f976c49c5f0>),
    ('upper', <built-in method upper of bytes object at 0x7f976c49c5f0>),
    ('zfill', <built-in method zfill of bytes object at 0x7f976c49c5f0>)
]
PINTOPINTO
decoded_code

<code object retinex_cau at 0x7f976c472d20, file "/home/lff/TIP/20190914_retinex/Network.py", line 152>
PINTOPINTO
import types
code =b'd\x01\x00|\x00\x00d\x00\x00d\x00\x00\ufffd\x02\x00d\x00\x00d\x00\x00\ufffd\x02\x00d\x00\x00d\x00\x00\ufffd\x02\x00d\x00\x00d\x01\x00\ufffd\x02\x00f\x04\x00\x19\x18d\x02\x00\x17}\x01\x00|\x00\x00d\x00\x00d\x00\x00\ufffd\x02\x00d\x00\x00d\x00\x00\ufffd\x02\x00d\x00\x00d\x00\x00\ufffd\x02\x00d\x01\x00d\x03\x00\ufffd\x02\x00f\x04\x00\x19}\x02\x00|\x02\x00|\x01\x00\x1bS'
raw_code = codecs.decode(code.encode('ascii'), 'base64')
decoded_code = marshal.loads(raw_code)
func2 = types.FunctionType(code, globals())
PINTOPINTO
pip3 install meta
import meta
import codecs
import marshal
import inspect

code = '4wEAAAAAAAAAAwAAAAcAAABTAAAAc2wAAABkAQB8AABkAABkAACFAgBkAABkAACFAgBkAABkAACF\nAgBkAABkAQCFAgBmBAAZGGQCABd9AQB8AABkAABkAACFAgBkAABkAACFAgBkAABkAACFAgBkAQBk\nAwCFAgBmBAAZfQIAfAIAfAEAG1MpBE7pAQAAAGfxaOOItfjkPukEAAAAqQApA9oBeFoEaWxsddoD\naW1ncgMAAAByAwAAAPopL2hvbWUvbGZmL1RJUC8yMDE5MDkxNF9yZXRpbmV4L05ldHdvcmsucHna\nC3JldGluZXhfY2F1mAAAAHMGAAAAAAE2AS4B\n'
raw_code = codecs.decode(code.encode('ascii'), 'base64')
decoded_code = marshal.loads(raw_code)

mc = meta.decompile(decoded_code)
meta.dump_python_source(mc)
\nillu = ((1 - x[:, :, :, :1]) + 1e-05)\nimg = x[:, :, :, 1:4]\n
PINTOPINTO
wget https://github.com/figment/unpyc3/raw/master/unpyc3.py
python3
import meta
import codecs
import marshal

code = '4wEAAAAAAAAAAwAAAAcAAABTAAAAc2wAAABkAQB8AABkAABkAACFAgBkAABkAACFAgBkAABkAACF\nAgBkAABkAQCFAgBmBAAZGGQCABd9AQB8AABkAABkAACFAgBkAABkAACFAgBkAABkAACFAgBkAQBk\nAwCFAgBmBAAZfQIAfAIAfAEAG1MpBE7pAQAAAGfxaOOItfjkPukEAAAAqQApA9oBeFoEaWxsddoD\naW1ncgMAAAByAwAAAPopL2hvbWUvbGZmL1RJUC8yMDE5MDkxNF9yZXRpbmV4L05ldHdvcmsucHna\nC3JldGluZXhfY2F1mAAAAHMGAAAAAAE2AS4B\n'
raw_code = codecs.decode(code.encode('ascii'), 'base64')
decoded_code = marshal.loads(raw_code)

print(decompile(decoded_code))

illu = 1 - x[(:, :, :, :1)] + 1e-05
img = x[(:, :, :, 1:4)]
return img/illu
PINTOPINTO
pip3 install uncompyle6
from uncompyle6.main import decompile
import codecs   
import marshal
import sys
code = '4wEAAAAAAAAAAwAAAAcAAABTAAAAc2wAAABkAQB8AABkAABkAACFAgBkAABkAACFAgBkAABkAACF\nAgBkAABkAQCFAgBmBAAZGGQCABd9AQB8AABkAABkAACFAgBkAABkAACFAgBkAABkAACFAgBkAQBk\nAwCFAgBmBAAZfQIAfAIAfAEAG1MpBE7pAQAAAGfxaOOItfjkPukEAAAAqQApA9oBeFoEaWxsddoD\naW1ncgMAAAByAwAAAPopL2hvbWUvbGZmL1RJUC8yMDE5MDkxNF9yZXRpbmV4L05ldHdvcmsucHna\nC3JldGluZXhfY2F1mAAAAHMGAAAAAAE2AS4B\n'
raw_code = codecs.decode(code.encode('ascii'), 'base64')
decoded_code = marshal.loads(raw_code)
decompile(None, decoded_code, sys.stdout)
# uncompyle6 version 3.8.0
# Python bytecode 3.5.2
# Decompiled from: Python 3.5.2 (default, Jan 26 2021, 13:30:48) 
# [GCC 5.4.0 20160609]
# Embedded file name: /home/lff/TIP/20190914_retinex/Network.py
illu = 1 - x[:, :, :, :1] + 1e-05
img = x[:, :, :, 1:4]
return img / illu
<uncompyle6.semantics.pysource.SourceWalker object at 0x7fd4e05d6748>
PINTOPINTO
def retinex_cau(x):
    illu = 1 - x[:, :, :, :1] + 1e-05
    img = x[:, :, :, 1:4]
    return img / illu

generic_utils.func_dump(retinex_cau)

('4wEAAAAAAAAAAwAAAAcAAABDAAAAc2wAAABkAQB8AABkAABkAACFAgBkAABkAACFAgBkAABkAACF\nAgBkAABkAQCFAgBmBAAZGGQCABd9AQB8AABkAABkAACFAgBkAABkAACFAgBkAABkAACFAgBkAQBk\nAwCFAgBmBAAZfQIAfAIAfAEAG1MpBE7pAQAAAGfxaOOItfjkPukEAAAAqQApA9oBeNoEaWxsddoD\naW1ncgMAAAByAwAAAPoHPHN0ZGluPtoLcmV0aW5leF9jYXUBAAAAcwYAAAAAATYBLgE=\n', None, None)
PINTOPINTO
code = "4wEAAAAAAAAAAQAAAAYAAAATAAAAcxkAAAB0AABqAQB8AABkAQCIAABkAgBkAwCDAQJTKQRO2gRh\neGlz2ghrZWVwZGltc1QpAtoBS9oEbWVhbikB2gFhKQHaDHNwYXRpYWxfZGltc6kA+jwvdXNyL2xv\nY2FsL2xpYi9weXRob24zLjUvZGlzdC1wYWNrYWdlcy9lZmZpY2llbnRuZXQvbW9kZWwucHnaCDxs\nYW1iZGE+XwAAAPMAAAAA\n"
raw_code = codecs.decode(code.encode('ascii'), 'base64')
decoded_code = marshal.loads(raw_code)
decompile(None, decoded_code, sys.stdout)

# uncompyle6 version 3.8.0
# Python bytecode 3.5.2
# Decompiled from: Python 3.5.2 (default, Jan 26 2021, 13:30:48) 
# [GCC 5.4.0 20160609]
# Embedded file name: /usr/local/lib/python3.5/dist-packages/efficientnet/model.py
return K.mean(a, axis=spatial_dims, keepdims=True)<uncompyle6.semantics.pysource.SourceWalker object at 0x7fd4de96ee48>
nano /usr/local/lib/python3.5/dist-packages/efficientnet/model.py

def block(inputs):
    x = inputs
    x = KL.Lambda(lambda a: K.mean(a, axis=spatial_dims, keepdims=True))(x) <---------- ココ
PINTOPINTO
from keras.utils import generic_utils
from keras.layers.core import Lambda

    def retinex_cau(x):
        illu = 1 - x[:, :, :, :1] + 1e-05
        img = x[:, :, :, 1:4]
        return img / illu

generic_utils.func_dump(retinex_cau)