# TensorFlow Function Currying in Slim NetFactory

Slim is widely used in TensorFlow. All networks , including ResNet, Inception and MobileNet, are wrapped by a net factory: nets_factory.py. A typical network call looks like:

The entry function get_network_fn(name, num_classes, weight_decay=0.0, is_training=False) receives merely four args. However, many networks accept more than four args (more precisely, three args here as the name indicates the network name). For example, resnet v2 accepts multiple args:

A problem naturally arises: What happened here? How to appropriately call the right network function?

The mystery lies in function currying. Currying is the technique of breaking down the evaluation of a function that takes multiple arguments into evaluating a sequence of single-argument functions. Slim network factory just exploits this advantage to break down the complex and multiple arguments into prerequiste arguments that are shared by all network entry functions and accessory arguments typically belong each individual network function.

Let’s again take a look at the wrapper function:

A decorator is applied to define the network_fn() which accepts **kwargs and **kwargs handles all the extra arguments. Therefore, a typical call of resnet might look like: