Model = self.model = Sequential()

This is probably a basic python question but it is one of those things that I can’t seem to let go and can’t find an answer to.

In the first class, when Vgg16 is instatiated by vgg = Vgg16(), this runs with no problem so I am not questioning the code.

But in trying to understand the code, there is this line:

def init(self):
self.FILE_PATH = 'http://files.fast.ai/models/'
self.create()
self.get_classes()

def create(self):
model = self.model = Sequential()
model.add(Lambda(vgg_preprocess, input_shape=(3,224,224), output_shape=(3,224,224)))
self.ConvBlock(2, 64)
self.ConvBlock(2, 128)

So I am assuming the changes to model are changes in self.model, i.e. they refer to the same thing as in:

class g():
def init(self):
m=self.m=6
print self.m, m
print self.m is m

h = g()

6 6
True

But when I modify m by itself, this changes:

class g():
def init(self):
m=self.m=6
m += 5
print self.m, m
print self.m is m

h = g()

6 11
False

I am confused about why changes to model are reflected in self.model and vice versa.

THanks

Johnn

@john1
I believe model is a mutable data type. I have not seen the code… is just my guess

Mutable datatypes are equivalent to pass by reference. Hence changes are reflected…

Non-mutable datatypes are equivalent to pass by value. Hence changes are not reflected…

Try your example with 2 data types:

  1. List - Mutable datatype
  2. Integer - Non-mutable data type…

List will reflect the changes.
Integer datatype will not reflect the changes