Lesson 7 - CAM AttributeError: 'Sequential' object has no attribute 'layer1'

This same question was addressed by @sam2 under the “Part 1 (2017)” category of the forum. See this link and Jeremy has updated the code in GitHub as suggested by Sam.

In short Sam suggested that the code be changed from:

sfs = [SaveFeatures(o) for o in [m.layer1, m.layer2, m.layer3, m.layer4]]

to

sfs = [SaveFeatures(o) for o in [m[-7], m[-6], m[-5], m[-4]]]

Sam also suggested a change in cell 16:

feat = np.maximum(0, sf.features[0])

to

feat = np.maximum(0, to_np(sf.features[0]))

The first change resolved problem 1, but I am now getting a problem with the “feat = …” statement, with or without Sam’s suggested change.

feat = np.maximum(0, to_np(sf.features[0]))
–> NameError: name ‘sf’ is not defined

Applying the change suggested by @sjcho did overcome the layers issue highlighted by @pete.condon, but I still had the above error with the “feat = …” statement. Any help would be appreciated.