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):
store_attr(‘model,dls,loss_func,lr,cbs,opt_func’)
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

output[0,cls].backward()

grad = hookg.stored 

w=grad[0].mean(dim=[1,2],keepdim=True)

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

print(cam_map.shape)

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

_,ax = plt.subplots()

x_dec.show(ctx=ax)

ax.imshow(cam_map.detach().cpu(),alpha=0.6,extent=(0,224,224,0),interpolation=‘bilinear’,cmap=‘magma’);

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