andersbll / nnet Goto Github PK
View Code? Open in Web Editor NEWNeural networks in NumPy/Cython
License: MIT License
Neural networks in NumPy/Cython
License: MIT License
Hi.
I am completely new in CNN and Python.
I wana to run your example cnn_mnist.py but I get the error:
line 7, in
import nnet
ImportError: No module named nnet
would you tell me what should I do. I use the pythonxy 2.7.10 sell.
BTW. I already run your setup.py and it was successful
hello, andersbll:
Thanks for your code. it is very useful for me.
i read your code and want to ask a question.
Line68 in layers.py:
self.dW = np.dot(self.last_input.T, output_grad)/n - self.weight_decay*self.W
In L2 regularization, i think this program need modify into
self.dW = np.dot(self.last_input.T, output_grad)/n + self.weight_decay*self.W
Would you tell me what you think to use "- self.weight_decay*self.W"?
B.R
heibanke
Thanks for your great work
I found some problem when running the example, I can't find the reason
when running the above two example, the following error pop up:
Traceback (most recent call last):
File "cnn_mnist.py", line 72, in
run()
File "cnn_mnist.py", line 62, in run
nn.fit(X_train, y_train, learning_rate=0.05, max_iter=3, batch_size=32)
File "F:\summerVacation\lib\site-packages\nnet\neuralnetwork.py", line 29, in fit
Y_one_hot = one_hot(Y)
File "F:\summerVacation\lib\site-packages\nnet\helpers.py", line 9, in one_hot
one_hot_labels[labels == c, c] = 1
IndexError: only integers, slices (:
), ellipsis (...
), numpy.newaxis (None
) and integer or boolean arrays are valid indices
I'm not sure why this happen.
Thank you so much for making such readable code for beginners in convolutional neural networks like me.
I am trying to get some results with this code using time-series, xyz acceleration data.
As opposed to images which are 2D, 3-channel data, time-series are 1D, 3-channel data. I have run the cnn_mnist examples included in this code, and have achieved satisfactory results. However, with the scaled time-series data that I have, I couldn't get any decent results with the same parameters and layer configurations. I suppose convolution computation for 1D and 2D is entirely different, and that I need to apply internal modifications if I want this to work. Please see below for the code I used.
Do I need to make modifications on the matrix operations level (convolution)? Where is this part in the code?
Note: I am also a python beginner, but I can understand the basic hierarchy of the code.
Code:
#!/usr/bin/env python
# coding: utf-8
import time
import numpy as np
import sklearn.datasets
import nnet
def run():
# Data (https://archive.ics.uci.edu/ml/datasets/Human+Activity+Recognition+Using+Smartphones)
# imgs has shape (n_imgs, n_channels_in, img_h, img_w)
# filters has shape (n_channels_in, n_channels_out, img_h, img_w)
# convout has shape (n_imgs, n_channels_out, img_h, img_w)
xtrain = np.genfromtxt('/home/sclab/UCI_HAR_Dataset/train/Inertial Signals/body_acc_x_trainScaled.csv', delimiter=',')
ytrain = np.genfromtxt('/home/sclab/UCI_HAR_Dataset/train/Inertial Signals/body_acc_y_trainScaled.csv', delimiter=',')
ztrain = np.genfromtxt('/home/sclab/UCI_HAR_Dataset/train/Inertial Signals/body_acc_z_trainScaled.csv', delimiter=',')
traindata = np.concatenate((xtrain, ytrain, ztrain), axis = 1)
X_train = np.reshape(traindata, (-1, 3, 1, 64))
y_train = np.genfromtxt('/home/sclab/UCI_HAR_Dataset/train/Inertial Signals/y_train.txt', dtype=int)
xtest = np.genfromtxt('/home/sclab/UCI_HAR_Dataset/test/Inertial Signals/body_acc_x_testScaled.csv', delimiter=',')
ytest = np.genfromtxt('/home/sclab/UCI_HAR_Dataset/test/Inertial Signals/body_acc_y_testScaled.csv', delimiter=',')
ztest = np.genfromtxt('/home/sclab/UCI_HAR_Dataset/test/Inertial Signals/body_acc_z_testScaled.csv', delimiter=',')
testdata = np.concatenate((xtest, ytest, ztest), axis = 1)
X_test = np.reshape(testdata, (-1, 3, 1, 64))
y_test = np.genfromtxt('/home/sclab/UCI_HAR_Dataset/test/Inertial Signals/y_test.txt', dtype=int)
n_classes = np.unique(y_train).size
# Setup convolutional neural network
nn = nnet.NeuralNetwork(
layers=[
nnet.Conv(
n_feats=12,
filter_shape=(3, 3),
strides=(1, 1),
weight_scale=0.1,
weight_decay=0.001,
),
nnet.Activation('relu'),
nnet.Pool(
pool_shape=(2, 2),
strides=(2, 2),
mode='max',
),
nnet.Conv(
n_feats=600,
filter_shape=(3, 3),
strides=(1, 1),
weight_scale=0.1,
weight_decay=0.001,
),
nnet.Activation('relu'),
nnet.Flatten(),
nnet.Linear(
n_out=n_classes,
weight_scale=0.1,
weight_decay=0.02,
),
nnet.LogRegression(),
],
)
# Train neural network
t0 = time.time()
nn.fit(X_train, y_train, learning_rate=0.05, max_iter=3, batch_size=32)
t1 = time.time()
print('Duration: %.1fs' % (t1-t0))
# Evaluate on test data
error = nn.error(X_test, y_test)
print('Test error rate: %.4f' % error)
if __name__ == '__main__':
run()
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.