diff --git a/python/README.md b/python/README.md index 01eab7f..3ed3bbe 100644 --- a/python/README.md +++ b/python/README.md @@ -1,3 +1,3 @@ -# skynet +SkyNet is a deep learning library designed for both efficiency and flexibility. It allows you to mix the flavours of deep learning programs together to maximize the efficiency and your productivity. -on development stage \ No newline at end of file +This package supports Linux, and Windows platforms. \ No newline at end of file diff --git a/python/libskynet/__init__.py b/python/libskynet/__init__.py index 80966da..e9663fc 100644 --- a/python/libskynet/__init__.py +++ b/python/libskynet/__init__.py @@ -1,4 +1,5 @@ -# +#!/usr/bin/env python + # SkyNet Project # Copyright (C) 2018 by Contributors # @@ -22,11 +23,17 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. +# coding: utf-8 + from __future__ import absolute_import import os import ctypes +from . import snNet +from . import snType +from . import snOperator + libname = 'libskynet.so' if os.name == 'nt': libname = 'libskynet.dll' @@ -36,6 +43,21 @@ _LIB = ctypes.CDLL(libname) -__all__ = ["snType", "snNet", "snOperator"] +def _snVersionLib() -> str: + """ + version library + :return: version + """ + + pfun = _LIB.snVersionLib + pfun.restype = None + pfun.argtypes = (ctypes.c_char_p,) + + ver = ctypes.create_string_buffer(32) + pfun(ver) + + return ver.value.decode("utf-8") +# current version +__version__ = _snVersionLib() \ No newline at end of file diff --git a/python/libskynet/snExample.py b/python/libskynet/snExample.py deleted file mode 100644 index d8fc1b1..0000000 --- a/python/libskynet/snExample.py +++ /dev/null @@ -1,76 +0,0 @@ -from libskynet import* -import numpy as np -import imageio -import random -import ctypes -import datetime -import os - - -# create net -net = snNet.Net() -net.addNode("In", snOperator.Input(), "C1") \ - .addNode("C1", snOperator.Convolution(10, -1, snType.calcMode.CUDA), "C2") \ - .addNode("C2",snOperator.Convolution(10, 0, snType.calcMode.CUDA), "P1 Crop1") \ - .addNode("Crop1", snOperator.Crop(snType.rect(0, 0, 487, 487)), "Rsz1") \ - .addNode("Rsz1", snOperator.Resize(snType.diap(0, 10), snType.diap(0, 25)), "Conc1") \ - .addNode("P1", snOperator.Pooling(snType.calcMode.CUDA), "C3") \ - \ - .addNode("C3", snOperator.Convolution(10, -1, snType.calcMode.CUDA), "C4") \ - .addNode("C4", snOperator.Convolution(10, 0, snType.calcMode.CUDA), "P2 Crop2") \ - .addNode("Crop2", snOperator.Crop(snType.rect(0, 0, 247, 247)), "Rsz2") \ - .addNode("Rsz2", snOperator.Resize(snType.diap(0, 10), snType.diap(0, 25)), "Conc2") \ - .addNode("P2", snOperator.Pooling(snType.calcMode.CUDA), "C5") \ - \ - .addNode("C5", snOperator.Convolution(10, 0, snType.calcMode.CUDA), "C6") \ - .addNode("C6", snOperator.Convolution(10, 0, snType.calcMode.CUDA), "DC1") \ - .addNode("DC1", snOperator.Deconvolution(10, snType.calcMode.CUDA), "Rsz3") \ - .addNode("Rsz3", snOperator.Resize(snType.diap(0, 10), snType.diap(10, 20)), "Conc2") \ - \ - .addNode("Conc2", snOperator.Concat("Rsz2 Rsz3"), "C7") \ - \ - .addNode("C7", snOperator.Convolution(10, 0, snType.calcMode.CUDA), "C8") \ - .addNode("C8", snOperator.Convolution(10, 0, snType.calcMode.CUDA), "DC2") \ - .addNode("DC2", snOperator.Deconvolution(10, snType.calcMode.CUDA), "Rsz4") \ - .addNode("Rsz4", snOperator.Resize(snType.diap(0, 10), snType.diap(10, 20)), "Conc1") \ - \ - .addNode("Conc1", snOperator.Concat("Rsz1 Rsz4"), "C9") \ - \ - .addNode("C9", snOperator.Convolution(10, 0, snType.calcMode.CUDA), "C10") - -convOut = snOperator.Convolution(1, 0, snType.calcMode.CUDA) -convOut.act = snType.active.sigmoid; -net.addNode("C10", convOut, "Output"); - -# loadImg - -pathImg = 'c:/C++/skyNet/example/unet/images/' -imgList = os.listdir(pathImg) - -pathLabel= 'c:/C++/skyNet/example/unet/labels/' -labelsList = os.listdir(pathLabel) - -bsz = 5 -lr = 0.001 -accuratSumm = 0. -inLayer = np.zeros((bsz, 1, 512, 512), ctypes.c_float) -outLayer = np.zeros((bsz, 1, 483, 483), ctypes.c_float) -targLayer = np.zeros((bsz, 1, 483, 483), ctypes.c_float) - -# cycle lern -for n in range(1000): - - targLayer[...] = 0 - - for i in range(bsz): - nimg = random.randint(0, len(imgList) - 1) - inLayer[i] = imageio.imread(pathImg + imgList[nimg]) - - targLayer[i] = np.resize(imageio.imread(pathLabel + labelsList[nimg]), (1, 483, 483)) / 255. - - acc = [0] # do not use default accurate - net.training(lr, inLayer, outLayer, targLayer, acc) - - accuratSumm += acc[0] - - print(datetime.datetime.now().strftime('%H:%M:%S'), n, "accurate", accuratSumm / (n + 1)) \ No newline at end of file diff --git a/python/libskynet/snLibInfo.py b/python/libskynet/snLibInfo.py deleted file mode 100644 index 91c7c8e..0000000 --- a/python/libskynet/snLibInfo.py +++ /dev/null @@ -1,46 +0,0 @@ -# -# SkyNet Project -# Copyright (C) 2018 by Contributors -# -# This code is licensed under the MIT License. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files(the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions : -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -from __init__ import _LIB -import ctypes - -"""Information about libskynet""" - -def _snVersionLib() -> str: - """ - version library - :return: version - """ - - pfun = _LIB.snVersionLib - pfun.restype = None - pfun.argtypes = (ctypes.c_char_p,) - - ver = ctypes.create_string_buffer(32) - pfun(ver) - - return ver.value.decode("utf-8") - -# current version -__version__ = _snVersionLib() diff --git a/python/libskynet/snNet.py b/python/libskynet/snNet.py index f32d405..1ed927a 100644 --- a/python/libskynet/snNet.py +++ b/python/libskynet/snNet.py @@ -23,10 +23,9 @@ # THE SOFTWARE. import ctypes -from __init__ import _LIB +from libskynet.__init__ import _LIB import json -from snBase import* -import snOperator +from libskynet.snBase import* import numpy class Net(): @@ -79,7 +78,7 @@ def getErrorStr(self) -> str: return err - def addNode(self, name : str, nd : snOperator, nextNodes : str): + def addNode(self, name : str, nd, nextNodes : str): """ add Node :param name: name node @@ -92,7 +91,7 @@ def addNode(self, name : str, nd : snOperator, nextNodes : str): return self - def updateNode(self, name : str, nd : snOperator) -> bool: + def updateNode(self, name : str, nd) -> bool: """ Update params node :param name: name node diff --git a/python/libskynet/snOperator.py b/python/libskynet/snOperator.py index b7d7b21..0194d83 100644 --- a/python/libskynet/snOperator.py +++ b/python/libskynet/snOperator.py @@ -22,7 +22,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from snType import * +from libskynet.snType import * class Input(): """Input layer.""" diff --git a/python/setup.py b/python/setup.py index 26826b3..3b41022 100644 --- a/python/setup.py +++ b/python/setup.py @@ -22,24 +22,35 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from setuptools import setup, find_packages - -"""Setup skynet package.""" +from __future__ import absolute_import import os import sys +from setuptools import find_packages + +kwargs = {} +if "--inplace" in sys.argv: + from distutils.core import setup + from distutils.extension import Extension +else: + from setuptools import setup + from setuptools.extension import Extension + kwargs = {'install_requires': ['numpy<=1.15.2,>=1.8.2', 'requests<2.19.0,>=2.18.4', 'graphviz<0.9.0,>=0.8.1'], 'zip_safe': False} + with open("README.md", "r") as fh: long_description = fh.read() CURRENT_DIR = os.path.normpath(os.path.dirname(__file__)) -libinfo_py = os.path.join(CURRENT_DIR, 'libskynet/snLibInfo.py') -libinfo = {'__file__': libinfo_py} -exec(compile(open(libinfo_py, "rb").read(), libinfo_py, 'exec'), libinfo, libinfo) -dll_path = os.listdir(os.path.join(CURRENT_DIR, 'dll')) -lib_path = [os.path.join(CURRENT_DIR, 'dll') + os.path.sep + p for p in dll_path] +if os.name == 'nt': + trgPath = 'lib/site-packages/libskynet' +else: + trgPath = 'lib/python3.5/dist-packages/libskynet' + +dll_path = os.listdir(os.path.join(CURRENT_DIR, 'lib')) +lib_path = [os.path.join(CURRENT_DIR, 'lib') + os.path.sep + p for p in dll_path] -__version__ = libinfo['__version__'] +__version__ = '1.0.1' setup( name="libskynet", @@ -49,7 +60,7 @@ description="neural net with blackjack and hookers", long_description=long_description, long_description_content_type="text/markdown", - data_files=[('lib/site-packages/libskynet', lib_path)], + data_files=[(trgPath, lib_path)], classifiers=[ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", @@ -57,12 +68,14 @@ 'Intended Audience :: Education', 'Intended Audience :: Science/Research', 'Programming Language :: C++', - 'Programming Language :: Python :: 3', + 'Programming Language :: Python', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3.6', 'Topic :: Scientific/Engineering', 'Topic :: Scientific/Engineering :: Artificial Intelligence', 'Topic :: Scientific/Engineering :: Mathematics', 'Topic :: Software Development', 'Topic :: Software Development :: Libraries', 'Topic :: Software Development :: Libraries :: Python Modules', - ] -) \ No newline at end of file + ], + **kwargs) \ No newline at end of file