Since Chainer has been updated to 2.0 and is no longer backward compatible, I will write the modified part so that it can be operated with 2.0.2 using AlexNet as an example.
I think that this part is mainly changed, and there is no need to change anything else.
In v1.x, class inheritance was performed directly in init part, but in v2.x, it has been changed to use with self.init_scope () :.
The notation of the init part has changed accordingly. Previously, fc_n = L.function (),
was described, but self.
was added asself.fc_n = L.function ()
, and the last,
is You don't need it anymore.
Note that if you forget to delete ,
here, you will get TypeError:'tuple' object is not callable
.
I was addicted to this error, wondering if the dataset was worse.
python:v1.x_Alex.py
class Alex(chainer.Chain):
def __init__(self):
super(Alex, self).__init__(
conv1=L.Convolution2D(None, 96, 11, stride=4),
conv2=L.Convolution2D(None, 256, 5, pad=2),
conv3=L.Convolution2D(None, 384, 3, pad=1),
conv4=L.Convolution2D(None, 384, 3, pad=1),
conv5=L.Convolution2D(None, 256, 3, pad=1),
fc6=L.Linear(None, 4096),
fc7=L.Linear(None, 4096),
fc8=L.Linear(None, 1000),
)
self.train = True
...
v2.x_Alex.py
class Alex(chainer.Chain):
def __init__(self):
super(Alex, self).__init__()
with self.init_scope():
self.conv1 = L.Convolution2D(None, 96, 11, stride=4)
self.conv2 = L.Convolution2D(None, 256, 5, pad=2)
self.conv3 = L.Convolution2D(None, 384, 3, pad=1)
self.conv4 = L.Convolution2D(None, 384, 3, pad=1)
self.conv5 = L.Convolution2D(None, 256, 3, pad=1)
self.fc6 = L.Linear(None, 4096)
self.fc7 = L.Linear(None, 4096)
self.fc8 = L.Linear(None, 1000)
...
In addition, the train that is reflected only during learning has been deleted from the function and specified in with chainer.using_config ()
.
model = L.Classifier(Alex())
with chainer.using_config('train',False):
y = (x)
Basically, it seems that it is common to set with this chainer.config
, and ʻusecudnnis also set with this. If you write
chainer.config.use_cudnn ='never'`, you can set not to use all at once.
There is nothing that doesn't work unless you change it, but the types of trainer.extend are increasing.
if extensions.PlotReport.available():
trainer.extend(extensions.PlotReport(['main/loss', 'validation/main/loss'],
'epoch', file_name='loss.png'))
trainer.extend(extensions.PlotReport(['main/accuracy', 'validation/main/accuracy'],
'epoch', file_name='accuracy.png'))
It seems that the graph of loss and accuracy is automatically output by writing, but it did not work well because it was said that there was no matplotlib that should be included in my environment.
It feels like I changed it and actually moved it, but the feed-forward network consisting only of general Linear is the same as before, but the network based on AlexNet is extremely learning. I feel like it's getting late. Probably badly written ...
Other changes are also written in this official Chainer docs
Recommended Posts