Created
December 24, 2021 15:05
-
-
Save shepai/69d533aef2aaeaf85ee7ab154dd01096 to your computer and use it in GitHub Desktop.
Network
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class model: | |
| def __init__(self,outcomes=10,numCells=28*28): | |
| self.model = Sequential() | |
| self.model.add(Dense(100, input_dim=numCells, activation='relu')) #4000 inputs compressed to 200 | |
| #model.add(Dense(100, activation='relu')) #keep abstracting information | |
| #model.add(Dense(10, activation='relu')) | |
| self.model.add(Dense(outcomes, activation='sigmoid')) #sigmoid is good for binary | |
| self.model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) | |
| def train(self,x,y,epochs=30,batch=32): | |
| history=self.model.fit(x,y,batch_size=batch,epochs=epochs,validation_split=0.1) | |
| self.history = history.history #gather training log | |
| def test(self,X,y): | |
| assert len(X)==len(y), "Error, the arrays do not match length" | |
| predictions = self.model.predict(X) | |
| count=0 | |
| for i in range(len(predictions)): | |
| pred=np.argmax(predictions[i]) | |
| if y[i]==pred: | |
| count+=1 | |
| return count/len(predictions) | |
| def save(self,name): | |
| self.model.save(''+name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment