This is a network.

Mrdflow 1.1.0 beta

下载方式

pip install mrdflow


使用说明：

1.1 Tensor数组

import mrdflow.autograd as ag
x = ag.arange(12)
#创建一个shape为(12,)的Tensor数组x,其功能等同于numpy.arange.

import mrdflow.autograd as ag
x = ag.arange(12)
y = ag.sin(x/2)
#求导出y对x导数

Tensor内置了许多函数，以下是个例子
import mrdflow.autograd as ag
import numpy as np
x = ag.arange(12).reshape(3,4)
y = ag.arange(12).reshape(4,3)
print(ag.dot(x,y))
#ag.dot：矩阵乘法函数
c = x.F
c = x.T
#Tensor.F:归一化，等同于numpy.ndarray.Flatten()
#Tensor.T:矩阵转置，等同于numpy.transpose(x)
v = x.numpy()
#将x转换成numpy.ndarray


1.2 Op算子

import mrdflow.autograd as ag
class TestOp(ag.Op):
def compute(inputs:list):
"""进行运算操作,将您的计算结果保存为self.re"""


2 神经网络

2.1 mnist

import mrdflow as mf
from mrdflow import autograd as ag
import numpy as np
x_train = data['x_train']
y_train = data['y_train']
def x_train_data(x):
return ag.Tensor(x)/255
def one_hot(y):
v = ag.zeros(10)
v[y] = 1
return v
x_train = list(map(x_train_data,x_train))
y_train = list(map(one_hot,y_train))
model = mf.Sequential([mf.Conv2d([28,28],1,[5,5]),
mf.MaxPooling2d([24,24],[4,4]),
mf.Dense(36,10,activation=mf.softmax)])
model.fit(x=x_train,y=y_train,epoch=1000,batch_size=100)
model.save('mnist.model')
#保存模型


Project details

Uploaded Source