Where do I go if I get errors with code from the book?
aliasal opened this issue · comments
If I have a problem with the code from the book, where do I go to get help?
Is there a repository for the code somewhere? At the moment I copy it from the ebook.
I followed along till Chapter 18, but here I get an error that I cannot resolve:
File "test3.py", line 35, in
model.train(X, y, validation_data=(X_test, y_test),
File "C:\Users\Arnd\Desktop 3\NNFS\Libraries.py", line 647, in train
output = self.forward(X, training=True)
File "C:\Users\Arnd\Desktop 3\NNFS\Libraries.py", line 694, in forward
self.input_layer.forward(X, training)
TypeError: forward() takes 2 positional arguments but 3 were given
I import all the Layer/Activations/Model.. classes from a file called Libraries
The calling code is:
import numpy as np
import nnfs
from nnfs.datasets import spiral_data, sine_data
from Libraries import Layer_Dense, Activation_ReLU, Activation_Softmax, Loss, Loss_CategoricalCrossentropy
from Libraries import Activation_Softmax_Loss_CategoricalCrossentropy, Optimizer_SGD, Optimizer_Adam, Optimizer_RMSprop
from Libraries import Optimizer_Adagrad, Layer_Dropout, Activation_Sigmoid, Loss_BinaryCrossentropy
from Libraries import Activation_Linear, Loss_MeanSquaredError, Loss_MeanAbsoluteError
from Libraries import Model, Layer_Input, Accuracy_Regression, Accuracy_Categorical
import matplotlib.pyplot as plt
nnfs.init()
Create dataset
X, y = spiral_data(samples=1000, classes=3)
X_test, y_test = spiral_data(samples=100, classes=3)
Instantiate the model
model = Model()
Add layers
model.add(Layer_Dense(2, 512, weight_regularizer_l2=5e-4,
bias_regularizer_l2=5e-4))
model.add(Activation_ReLU())
model.add(Layer_Dropout(0.1))
model.add(Layer_Dense(512, 3))
model.add(Activation_Softmax())
Set loss, optimizer and accuracy objects
model.set(
loss=Loss_CategoricalCrossentropy(),
optimizer=Optimizer_Adam(learning_rate=0.05, decay=5e-5),
accuracy=Accuracy_Categorical()
)
Finalize the model
model.finalize()
Train the model
model.train(X, y, validation_data=(X_test, y_test),
epochs=10000, print_every=100)
Found my error:
I overlooked that the Layer_Input class had changed the forward method signature from
def forward(self, inputs):
to
def forward(self, inputs, training)