I am trying to create neural network from scratch using python. But I am getting this kind of error. can anyone help me?
Code:
import numpy as py
import nnfs as nf ## import nnfs this is
from nnfs.datasets import spiral_data
nf.init() # reset to the same number as before to check whethere it works.
X = [[1, 2, 3, 2.5],
[2.0, 5.0, 1.0, 2.0],
[1.5, 2.7, 3.3,0.8]]
##############
##weights =[[0.2, 0.8, 0.4, 0.5],[0.2, 0.8, 0.4, 0.5],[0.2, 0.8, 0.4, 0.5]]
##biases = [2,3,0.5]
##weights2 =[[0.1,-0.14,0.5],[-.5, 0.12, -.33],[-0.44, 0.73,-.13]]
##biases2 = [-1,2,-.5]
##layer1_output = py.dot(weights,py.transpose(input)) + biases # Dot product give shape of the each neuron.
##layer2_output = py.dot(layer1_output,py.array(weights2).T) + biases2
##print(layer2_output)
#########################
##GENERATE DATASET###
x,y = spiral_data(100,3)
class Layer_Dense:
def __init__(self, n_inputs,n_neurons): ##
self.weights = 0.10 * py.random.randn(n_inputs,n_neurons) # size of input, shape of weight (shape of neuron = neuron X transposed input. )
self.biases = py.zeros((1,n_neurons))
def forward(self,inputs):
self.output = py.dot(inputs, self.weights) + self.biases
class Activation_ReLU:
def forward(self, inputs):
self.output = py.maximum(0,inputs)
layer1 = Layer_Dense(2,5) # number of inputs , number of neurons
activation1 = Activation_ReLU()
layer1.forward(X)
print(layer1.output)
activation1.forward(layer1.ouput)
print(activation1.output)
File "/Users/eungbaekkim9andy/coding/python/NeuralNetwork/NeuralNetwork.py", line 36, in <module>
layer1.forward(X)
File "/Users/eungbaekkim9andy/coding/python/NeuralNetwork/NeuralNetwork.py", line 27, in forward
self.output = py.dot(inputs, self.weights) + self.biases
File "/Users/eungbaekkim9andy/miniconda3/lib/python3.9/site-packages/nnfs/core.py", line 22, in dot
return orig_dot(*[a.astype('float64') for a in args], **kwargs).astype('float32')
File "/Users/eungbaekkim9andy/miniconda3/lib/python3.9/site-packages/nnfs/core.py", line 22, in <listcomp>
return orig_dot(*[a.astype('float64') for a in args], **kwargs).astype('float32')
AttributeError: 'list' object has no attribute 'astype'
I tried to change n_inputs to np.array(n_inputs ) but I don't think it is working.
You have a typo in:
activation1.forward(layer1.ouput)
Also, not sure if this output is what you're looking for but I changed to a lowercase (x) here:
layer1.forward(x)
print(layer1.output)
activation1.forward(layer1.output)
print(activation1.output)