{"id":26090647,"url":"https://github.com/e1evenn/shinnosuke","last_synced_at":"2025-09-01T17:41:03.123Z","repository":{"id":57466796,"uuid":"201182833","full_name":"E1eveNn/shinnosuke","owner":"E1eveNn","description":"A keras-like API deep learning framework,realized by Numpy only.Support  CNN, RNN, LSTM, Dense, etc.","archived":false,"fork":false,"pushed_at":"2020-04-16T12:12:23.000Z","size":252,"stargazers_count":21,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T06:12:50.098Z","etag":null,"topics":["deep-learning","deep-learning-algorithms","deep-learning-framework","deep-learning-library","deep-learning-tutorial","deep-neural-networks"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/E1eveNn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-08T05:12:57.000Z","updated_at":"2022-10-06T11:19:59.000Z","dependencies_parsed_at":"2022-09-10T03:43:55.943Z","dependency_job_id":null,"html_url":"https://github.com/E1eveNn/shinnosuke","commit_stats":null,"previous_names":["elevennn/shinnosuke"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/E1eveNn%2Fshinnosuke","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/E1eveNn%2Fshinnosuke/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/E1eveNn%2Fshinnosuke/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/E1eveNn%2Fshinnosuke/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/E1eveNn","download_url":"https://codeload.github.com/E1eveNn/shinnosuke/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248525138,"owners_count":21118619,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","deep-learning-algorithms","deep-learning-framework","deep-learning-library","deep-learning-tutorial","deep-neural-networks"],"created_at":"2025-03-09T09:53:41.777Z","updated_at":"2025-04-12T06:13:16.559Z","avatar_url":"https://github.com/E1eveNn.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Shinnosuke : Deep Learning Framework\n\n\u003cdiv align=center\u003e\n\t\u003cimg src=\"https://gss1.bdstatic.com/9vo3dSag_xI4khGkpoWK1HF6hhy/baike/w%3D268%3Bg%3D0/sign=625eaa79a864034f0fcdc50097f81e0c/8c1001e93901213f91ab2a7857e736d12e2e95fd.jpg\" width=\"\"\u003e\n\u003c/div\u003e\n\n\n\n## Descriptions\n\nShinnosuke is a high-level neural network which has almost the same API to Keras with slightly differences. It was written by Python only, and dedicated to realize experimentations quickly.\n\nHere are some features of Shinnosuke:\n\n1. Based on **Numpy** (CPU version)  and **native** to Python.   [GPU Version](https://github.com/eLeVeNnN/shinnosuke-gpu)\n2. **Without** any other **3rd-party** deep learning library.\n3. **Keras-like API**, several basic AI Examples are provided, easy to get start.\n4. Support commonly used models such as: *Dense, Conv2D, MaxPooling2D, LSTM, SimpleRNN, etc*.\n5. **Sequential** model (for most  sequence network combinations ) and **Functional** model (for resnet, etc) are implemented.\n6. Training is conducted on forward **graph** and backward **graph**.\n7. **Autograd** is supported .\n\nShinnosuke is compatible with: **Python 3.x (3.6 is recommended)**\n\n`###################################### \\^^shinnosuke documents^^/ ######################################`\n\n\t\t\t\t\t\t     \n\u003cdiv align=center\u003e\u003ca href=https://github.com/eLeVeNnN/shinnosuke/blob/master/docs/imgs/Shinnosuke-API.ipynb\u003eJupyter Notebook\u003c/a\u003e\u003c/div\u003e\n\u003cdiv align=center\u003e\u003ca href=https://github.com/eLeVeNnN/shinnosuke/blob/master/docs/imgs/Shinnosuke-API.md\u003eMarkdown\u003c/a\u003e\u003c/div\u003e\n\n\n------\n\n\n\n## Getting started\n\nThe core networks of Shinnosuke is a model, which provide a way to combine layers. There are two model types: `Sequential` (a linear stack of layers) and `Functional` (build  a graph for layers).\n\nHere is a example of `Sequential` model:\n\n```python\nfrom shinnosuke.models import Sequential\n\nm = Sequential()\n```\n\nUsing `.add()` to connect layers:\n\n```python\nfrom shinnosuke.layers import Dense\n\nm.add(Dense(n_out=500, activation='relu', n_in=784))  #must be specify n_in if current layer is the first layer of model\nm.add(Dense(n_out=10, activation='softmax'))  #no need to specify n_in as shinnosuke will automatic calculate the input and output shape\n```\n\nHere are some differences with Keras, n_out and n_in are named units and input_dim in Keras respectively.\n\nOnce you have constructed your model, you should configure it with `.compile()` before training:\n\n```python\nm.compile(loss='sparse_categorical_crossentropy', optimizer='sgd')\n```\n\nIf you apply softmax to multi-classify task and your labels are one-hot encoded vectors/matrix, you shall specify loss as  sparse_categorical_crossentropy, otherwise use categorical_crossentropy. (While in Keras categorical_crossentropy supports for one-hot encoded labels). And Shinnosuke model only supports one metrics--**accuracy**, which no need to specify in `compile`.\n\nUse `print()` function to see details of model:\n\n```python\nprint(m)\n# you shall see \n***************************************************************************\nLayer(type)          Output Shape         Param        Connected to   \n###########################################################################\nDense                (None, 500)          392500       \n              \n---------------------------------------------------------------------------\nDense                (None, 10)           5010         Dense          \n---------------------------------------------------------------------------\n***************************************************************************\nTotal params: 397510\nTrainable params: 397510\nNon-trainable params: 0\n```\n\nHaving finished `compile`, you can start training your data in batches:\n\n```python\n#trainX and trainy are Numpy arrays --for 2 dimension data, trainX's shape should be (training_nums,input_dim)\nm.fit(trainX, trainy, batch_size = 128, epochs = 5, validation_ratio = 0., draw_acc_loss = True)\n```\n\nBy specify `validation_ratio` = `(0.0,1.0]`, shinnosuke will split validation data from training data according to validation_ratio, otherwise validation_ratio=0. means no validation data. Alternatively you can  feed validation_data manually:\n\n```python\nm.fit(trainX, trainy, batch_size = 128, epochs = 5, validation_data = (validX, validy), draw_acc_loss = True)\n```\n\nIf `draw_acc_loss` = **True**, a dynamic updating figure will be shown in the training process, like below:\n\n\u003cdiv align=center\u003e\n\t\u003cimg src=\"https://github.com/eLeVeNnN/shinnosuke/blob/master/docs/imgs/draw_acc.png\" width=\"\"\u003e\n\u003c/div\u003e\n\n\nOnce completing training your model, you can save or load your model by `save()` / `load()`, respectively.\n```python\nm.save(save_path)\nm.load(model_path)\n```\n\n\nEvaluate your model performance by `.evaluate()`:\n\n```python\nacc, loss = m.evaluate(testX, testy, batch_size=128)\n```\n\nOr obtain predictions on new data:\n\n```python\ny_hat = m.predict(x_test)\n```\n\n\n\nFor `Functional` model, first instantiate an `Input` layer:\n\n```python\nfrom shinnosuke.layers import Input\n\nX_input = Input(shape = (None, 1, 28, 28))   #(batch_size,channels,height,width)\n```\n\nYou need to specify the input shape, notice that for Convolutional networks,data's channels must be in the `axis 1` instead of `-1`, and you should state batch_size as None which is unnecessary in Keras.\n\nThen Combine your layers by functional API:\n\n```python\nfrom shinnosuke.models import Model\nfrom shinnosuke.layers import Conv2D,MaxPooling2D\nfrom shinnosuke.layers import Activation\nfrom shinnosuke.layers import BatchNormalization\nfrom shinnosuke.layers import Flatten,Dense\n\nX = Conv2D(8, (2, 2), padding = 'VALID', initializer = 'normal', activation = 'relu')(X_input)\nX = MaxPooling2D((2, 2))(X)\nX = Flatten()(X)\nX = Dense(10, initializer = 'normal', activation = 'softmax')(X)\nmodel = Model(inputs = X_input, outputs = X)  \nmodel.compile(optimizer = 'sgd', loss = 'sparse_categorical_cross_entropy')\nmodel.fit(trainX, trainy, batch_size = 256, epochs = 80, validation_ratio = 0.)\n```\n\nPass inputs and outputs layer to `Model()`, and then compile and fit model like `Sequential`model.\n\n\n\nBuilding an image classification model, a question answering system or any other model is just as convenient and fast~\n\nIn the [Examples folder](https://github.com/eLeVeNnN/shinnosuke/Examples/) of this repository, you can find more advanced models.\n\n------\n\n## Both dynamic and static graph features\n\nAs you will see soon in below, Shinnosuke has two basic classes - Layer and Node. For Layer, operations between layers can be described like this (here gives an example of '+' ):\n\n```py\nfrom shinnosuke.layers import Input,Add\nfrom shinnosuke.layers import Dense\n\nX = Input(shape = (3, 5))\nX_shortcut = X\nX = Dense(5)(X)  #Dense will output a (3,5) tensor\nX = Add()([X_shortcut, X])\n```\n\nMeanwhile Shinnosuke will construct a graph as below:\n\n\u003cdiv align=center\u003e\n\t\u003cimg src=\"https://github.com/eLeVeNnN/shinnosuke/blob/master/docs/imgs/layer_graph.jpg\" width=\"300px\",height=\"200px\"\u003e\n\u003c/div\u003e\n\n\n\n\n\n While Node Operations have both dynamic graph and static graph features:\n\n```python\nfrom shinnosuke.layers.Base import Variable\n\nx = Variable(3)\ny = Variable(5)\nz = x + y  \nprint(z.get_value())\n```\n\nYou suppose get value 8, at same time shinnosuke construct a graph as below:\n\n\u003cdiv align=center\u003e\n\t\u003cimg src=\"https://github.com/eLeVeNnN/shinnosuke/blob/master/docs/imgs/node_graph.jpg\" width=\"300px\",height=\"200px\"\u003e\n\u003c/div\u003e\n\n\n\n## Autograd\n\nWhat is autograd? In a word, It means automatically calculate the network's gradients without any prepared backward codes for users, Shinnosuke's autograd supports for several operators, such as +, -, *, /, etc... Here gives an example:\n\nFor a simple fully connected neural network, you can use `Dense()` to construct it:\n\n```python\nfrom shinnosuke.models import Sequential\nfrom shinnosuke.layers import Dense\nimport numpy as np\n\n#announce a Dense layer\nfullyconnected = Dense(4, n_in = 5)\nm = Sequential()\nm.add(fullyconnected)\nm.compile(optimizer = 'sgd', loss = 'mse')  #don't mean to train it, use compile to initialize parameters\n#initialize inputs\nnp.random.seed(0)\nX = np.random.rand(3, 5)\n#feed X as fullyconnected's inputs\nfullyconnected.feed(X, 'inputs')\n#forward\nfullyconnected.forward()\nout1 = fullyconnected.get_value()\nprint(out1.get_value())\n#feed gradient to fullyconnected\nfullyconnected.feed(np.ones_like(out1), 'grads')\n#backward\nfullyconnected.backward()\nW, b = fullyconnected.variables\nprint(W.grads)\n```\n\nWe can also construct the same layer by using following codes:\n\n```python\nfrom shinnosuke.layers import Variable\n\na = Variable(X) # the same as X in previous fullyconnected\nc = Variable(W.get_value())  # the same value as W in previous fullyconnected\nd = Variable(b.get_value())  # the same value as b in previous fullyconnected\nout2 = a @ c + d   # @ represents for matmul\nprint(out2.get_value())\nout2.grads = np.ones_like(out2.get_value())   #specify gradients\n# by using grad(),shinnosuke will automatically calculate the gradient from out2 to c\nc.grad()\nprint(c.grads)\n```\n\nGuess what? out1 has the same value of out2, and so did W and c's grads. This is the magic autograd of shinnosuke. **By using this feature, users can implement other networks as wishes without writing any backward codes.**\n\nSee autograd example in [Here!](https://github.com/eLeVeNnN/shinnosuke-gpu/blob/master/Examples/autograd.ipynb)\n\n## Installation\n\nBefore installing Shinnosuke, please install the following **dependencies**:\n\n- Numpy = 1.15.0 (recommend)\n- matplotlib = 3.0.3 (recommend)\n\nThen you can install Shinnosuke by using pip:\n\n`$ pip install shinnosuke`\n\n**Installation from Github source will be supported in the future.**\n\n------\n\n\n\n## Supports\n\n### Two basic class:\n\n#### - Layer:\n\n- Dense\n- Flatten\n- Conv2D\n- MaxPooling2D\n- MeanPooling2D\n- Activation\n- Input\n- Dropout\n- Batch Normalization\n- Layer Normalization\n- Group Normalization\n- TimeDistributed\n- SimpleRNN\n- LSTM\n- Embedding\n- GRU (waiting for implemented)\n- ZeroPadding2D\n- Add\n- Minus\n- Multiply\n- Matmul\n\n\n\n#### - Node:\n\n- Variable\n- Constant\n\n\n\n### Optimizers\n\n- StochasticGradientDescent\n- Momentum\n- RMSprop\n- AdaGrad\n- AdaDelta\n- Adam\n\nWaiting for implemented more\n\n### Objectives\n\n- MeanSquaredError\n- MeanAbsoluteError\n- BinaryCrossEntropy\n- SparseCategoricalCrossEntropy\n- CategoricalCrossEntropy \n\n### Activations\n\n- Relu\n- Linear\n- Sigmoid\n- Tanh\n- Softmax\n\n### Initializations\n\n- Zeros\n- Ones\n- Uniform\n- LecunUniform\n- GlorotUniform\n- HeUniform\n- Normal\n- LecunNormal\n- GlorotNormal\n- HeNormal\n- Orthogonal\n\n### Regularizes\n\nwaiting for implement.\n\n### Utils\n\n- get_batches (generate mini-batch)\n- to_categorical (convert inputs to one-hot vector/matrix)\n- concatenate (concatenate Nodes that have the same shape in specify axis)\n- pad_sequences (pad sequences to the same length)\n\n## Contact\n\n- Email: eleven_1111@outlook.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fe1evenn%2Fshinnosuke","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fe1evenn%2Fshinnosuke","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fe1evenn%2Fshinnosuke/lists"}