Book typo?

Physical book page 509
def mse_grad uses inp.shape[0] where as page 511 class Mse backwards uses targ.shape[0]. It works with inp.shape[0]

1 Like

Page 537

Note the book has store_attr(self,… The self is not required. Google suggests somebody removed the requirement.

class Learner:
def init(self,model,dls,loss_func,lr,cbs,opt_func=SGD):
print(self.stored_args) #To prove the assignment
for cb in cbs: cb.learner = self

store_attr is a useful utility to assign self to to avoid typing self.a,self.b,self.c = a,b,c

I addition the Learner class is quite large and I think I miss-typed it so
[f for f in dir([f for f in dir(ClassName) if not f.startswith(’’)]) if not f.startswith(’’)]
is a useful tool to check alignment.

Just a suggestion with CAM

def mytest(xyz):

cls = 1

with HookBwd(learn.model[0][-xyz]) as hookg:

with Hook(learn.model[0][-xyz]) as hook:

   output = learn.model.eval()(x.cuda())

   act = hook.stored


grad = hookg.stored 


cam_map = (w* act[0]).sum(0)


x_dec = TensorImage(dls.train.decode((x,))[0][0])

_,ax = plt.subplots()


return 0

for wxyz in 6,5,4,3,2,1 : mytest(wxyz)

This show the activation map so the convolution starts to understand the cat.

Regards Conwyn