Closed auroua closed 6 years ago
π Hi, we support this with tl.models
now , see here
================== Hi, TL provides' SlimNetsLayer that can use all Google TF-Slim's pre-tained model here. This is an example for Inception V3 (click)
@luomai @lgarithm
I am thinking to release an API that help people import any type of model without knowing anything about slim or other resources.
Something like:
Get the whole model:
>>> net = tl.model.get_model("inceptionv3", last_layer=True)
>>. print(net.input_placeholder) # <-- where to feed the data in.
... (None, 299, 299, 3)
Get just a part of the model:
>>> net = tl.model.get_model("inceptionv3", layer_name="conv3_2")
Any idea about how to design the API ?
Shall we also provide the following syntax sugar if it is possible to do so in python?
net = tl.models["inceptionv3"][:-1]
net = tl.models["inceptionv3"]["conv3_2"]
related discussion: https://github.com/tensorlayer/tensorlayer/issues/380
I have implemented Resent
in tensorlayer
which can be created by
nets = get_resnet(x, 1000, 50, sess)
The code can load the tf-slim
pre-trained ckpt file
, but I found the inference results have some differences with the tf-slim
model.
The code can be found here.
@zsdonghao The model API can allow model specific parameter as follows:
net = tl.models.inceptionv3(**args) # import inception v3 model with args
The API shall also allow "partially reusing the model based on layers" for transfer learning, for example.
net = tl.models.inceptionv3(**args)[:-1] # reuse model and remove last layer
net = tl.models.inceptionv3(**args)[`conv3_2`] # reuse model until conv3_2 layer
x = tf.placeholder(tf.float32, [None, 224, 224, 3])
# get the whole model
vgg = tl.models.VGG16(x)
# restore pre-trained VGG parameters
vgg.restore_params(sess)
# use pre-trained VGG
softmax = tf.nn.softmax(vgg.outputs)
...
x = tf.placeholder(tf.float32, [None, 224, 224, 3])
# get VGG without the last layer
x = tf.placeholder(tf.float32, [None, 224, 224, 3])
# get VGG without the last layer
vgg = tl.models.VGG16(x, end_with='fc2_relu')
# add one more layer
net = tl.layers.DenseLayer(vgg, 100, name='out')
# initialize all parameters
sess = tf.InteractiveSession()
tl.layers.initialize_global_variables(sess)
# restore pre-trained VGG parameters
vgg.restore_params(sess)
# train your own classifier (only update the last layer)
train_params = tl.layers.get_variables_with_name('out')
β¦
x1 = tf.placeholder(tf.float32, [None, 224, 224, 3])
x2 = tf.placeholder(tf.float32, [None, 224, 224, 3])
# get VGG without the last layer
vgg1 = tl.models.VGG16(x1, end_with='fc2_relu')
# reuse parameters of vgg1, but use different input
vgg2 = tl.models.VGG16(x2, end_with='fc2_relu', reuse=True)
# restore pre-trained VGG parameters (as they share parameters, donβt need to restore vgg2)
sess = tf.InteractiveSession()
vgg1.restore_params(sess)
TensorLayer already have some implementations, just wrap them up!
then provide examples in documentation along with the APIs, and tutorial_models_xxx.py
in here
https://github.com/tensorlayer/tensorlayer/issues/394
We can save the model structure into TL graph, and the parameters into TL npz file.
TF .ckpt --> TL .npz
TF .pb --> TL graph
what kind of data format will be used for TL graph?
We might need to use pickle if we want to restore the network from saved file.
https://github.com/tensorlayer/tensorlayer/pull/461 tl.models.SqueezeNetV1
which uses ConcatLayer
@lgarithm
https://github.com/tensorlayer/tensorlayer/pull/465 tl.models.MobileNetV1
which uses DepthwiseConv2d
@lgarithm
final_endpoint
https://github.com/tensorflow/models/blob/master/research/slim/nets/inception_resnet_v2.py#L125
@luomai TODO list : https://github.com/tensorlayer/pretrained-models/blob/master/README.md
hi, I close this issue, feel free to reopen it if you want to discuss.
Could you support the network architecture like
vgg
,resnet
easily to use. If I want to useresnet
inPytorch
, I only need to write the following two lines code:But in
tensorlayer
, I have to define the network architecture by myself and then load the pretrained parameters.