def model_constructor(f): """ Wraps the function 'f' which returns the network. An extra field 'constructor' is added to the network returned by 'f'. This field contains an instance of the 'NetConstructor' class, which contains the information needed to re-construct the network, such as the name of the function 'f', the function arguments etc. Thus, the network can be easily constructed from a saved checkpoint by calling NetConstructor.get() function. """ @wraps(f) def f_wrapper(*args, **kwds): net_constr = NetConstructor(f.__name__, f.__module__, args, kwds) output = f(*args, **kwds) if isinstance(output, (tuple, list)): # Assume first argument is the network output[0].constructor = net_constr else: output.constructor = net_constr return output return f_wrapper
时间: 2024-02-14 14:32:37 浏览: 120
setter-on-constructor-prototype.rar_The Next
这段代码是用Python写的,它是一个装饰器函数,用于包装一个返回神经网络的函数。它会给返回的网络对象添加一个名为'constructor'的属性,这个属性包含了一些信息,比如函数名、函数参数等等,这些信息可以用于在需要的时候重新构建网络。如果返回的是一个元组或列表,它会假设第一个元素是网络对象,并给它添加'constructor'属性。最后返回包装后的函数对象。
阅读全文