Package: zWell-model
ZWell-modelintroduceA deep learning model library that supports various deep network models and transformations to libraries such as Keras.
With this tool, it is easy to construct neural network objects that can be used for any API, saving additional API
learning time.Acquisition method通过 pip 工具进行库的安装，也可以通过GitHub中的源码手动装载。pipinstallzWell-modelCurrent developments这里展示的是当前 zWell-model 支持的深度学习模型，以及其支持接入的第三方库等更详细的情况。Neural Network Nameby referenceSupport access to kerasSupported versionBasic Convolutional First EditionzWell_model.ConvNetV1yesv0.0.1.20230514Basic Convolutional Second EditionzWell_model.ConvNetV2yesv0.0.1.20230514Residual Neural Network First EditionzWell_model.ResNetV1yesv0.0.1.20230514Dense Neural Network First EditionzWell_model.DenseNetV1yesv0.0.2.20230528Usage examplesThere are many neural network implementations in this library that support conversion to various library model objects.
The following are relevant examples.Basic Convolutional Neural NetworksThe basic convolutional neural network contains the most basic network structure, which compromises learning speed and
accuracy, and has two versions in total.first editionA convolutional neural network with learning speed as its main core can improve learning speed for a large amount of
data with almost identical features.importzWell_model# Obtaining the first type of convolutional neural networkresNet=zWell_model.ConvNetV1(# The number of additional convolutional layers to be added above the specified infrastructure is 4. TODO defaults to 1model_layers_num=4,# Specify the step size in the four convolutional layersstride=[1,2,1,2],# Specify the input dimension of convolutional neural networksinput_shape=(None,32,32,3),# Specify classification quantityclasses=10)Second EditionThe convolutional neural network, whose core is learning speed and preventing overfitting, can improve learning speed
and model accuracy for a large number of data with diversified features.importzWell_model# Obtaining the second type of convolutional neural networkresNet=zWell_model.ConvNetV2(# The number of additional convolutional layers to be added above the specified infrastructure is 1. TODO defaults to 1model_layers_num=1,# Specify the step size in the one convolutional layersstride=[1],# Specify the input dimension of convolutional neural networksinput_shape=(32,32,3),# Specify classification quantityclasses=10)Example of using basic convolutional neural networksWhat is displayed here is the operation of converting the basic convolutional neural network series into models in Keras
and calling them.# This is an example Python script.importnumpyasnpfromkeras.datasetsimportcifar10fromkeras.optimizersimportAdamfromlivelossplotimportPlotLossesKerasimportzWell_model# Obtaining a dataset(x_train,y_train),(x_test,y_test)=cifar10.load_data()# Data standardization and dimension expansionx_train=x_train.astype(np.float32).reshape(-1,32,32,3)/255.x_test=x_test.astype(np.float32).reshape(-1,32,32,3)/255.# Obtaining the second type of convolutional neural networkresNet=zWell_model.ConvNetV2(# The number of additional convolutional layers to be added above the specified infrastructure is 1. TODO defaults to 1model_layers_num=1,# Specify the step size in the one convolutional layersstride=[1],# Specify the input dimension of convolutional neural networksinput_shape=(32,32,3),# Specify classification quantityclasses=10)# Converting to the network model of Kerasmodel=resNet.to_keras_model()model.summary()# Start building the modelmodel.compile(loss='sparse_categorical_crossentropy',optimizer=Adam(learning_rate=0.001),metrics=['acc'])# Start training the modelmodel.fit(x=x_train,y=y_train,validation_data=(x_test,y_test),batch_size=32,epochs=30,callbacks=[PlotLossesKeras()],verbose=1)Residual neural networkYou can obtain the general object of the residual neural network object from ZWell model in the following way.importzWell_model# Obtaining residual neural networkresNet=zWell_model.ResNetV1(# Specify the number of residual blocks as 4 TODO defaults to 4model_layers_num=4,# Specify the number of output channels in the four residual blocksk=[12,12,12,12],# Specify the step size in the four residual blocksstride=[1,2,1,2],# Specify the input dimension of the residual neural networkinput_shape=(32,32,3),# Specify classification quantityclasses=10)Directly convert the obtained residual neural network object into a neural network model object in Keras, enabling it to
be supported by Keras.# This is an example Python script.importnumpyasnpfromkeras.datasetsimportcifar10fromkeras.optimizersimportAdamfromlivelossplotimportPlotLossesKerasimportzWell_model# Obtaining a dataset(x_train,y_train),(x_test,y_test)=cifar10.load_data()# data standardizationx_train,x_test=x_train.astype(np.float32)/255.,x_test.astype(np.float32)/255.# Obtaining residual neural networkresNet=zWell_model.ResNetV1(# Specify the number of residual blocks as 4 TODO defaults to 4model_layers_num=4,# Specify the number of output channels in the four residual blocksk=[12,12,12,12],# Specify the step size in the four residual blocksstride=[1,2,1,2],# Specify the input dimension of the residual neural networkinput_shape=(32,32,3),# Specify classification quantityclasses=10)# Converting to the network model of Kerasmodel=resNet.to_keras_model()model.summary()# Start building the modelmodel.compile(loss='sparse_categorical_crossentropy',optimizer=Adam(learning_rate=0.001),metrics=['acc'])# Start training the modelmodel.fit(x=x_train,y=y_train,validation_data=(x_test,y_test),batch_size=32,epochs=30,callbacks=[PlotLossesKeras()],verbose=1)稠密神经网络You can obtain dense neural network models from the ZWell mode library in the following way.importzWell_model# Obtaining dense neural networksresNet=zWell_model.dense_net1.DenseNetV1(# Specify the number of dense blocks as 3 TODO defaults to 4model_layers_num=3,# Specify the convolution step size in the transition layer after 2 dense blocksstride=[1,1,1],# Specify the input dimension of a dense neural networkinput_shape=(32,32,3),#     # Specify classification quantityclasses=10)Convert the obtained dense neural network object into a deep neural network object in the Keras library.# This is an example Python script.importnumpyasnpfromkeras.datasetsimportcifar10fromkeras.optimizersimportAdamfromlivelossplotimportPlotLossesKerasimportzWell_model# Obtaining a dataset(x_train,y_train),(x_test,y_test)=cifar10.load_data()# data standardizationx_train,x_test=x_train.astype(np.float32)/255.,x_test.astype(np.float32)/255.# Obtaining dense neural networksresNet=zWell_model.dense_net1.DenseNetV1(# Specify the number of dense blocks as 3 TODO defaults to 4model_layers_num=3,# Specify the convolution step size in the transition layer after 2 dense blocksstride=[1,1,1],# Specify the input dimension of a dense neural networkinput_shape=(32,32,3),#     # Specify classification quantityclasses=10)print(resNet)# Converting to the network model of Kerasmodel=resNet.to_keras_model()model.summary()# Start building the modelmodel.compile(loss='sparse_categorical_crossentropy',optimizer=Adam(learning_rate=0.001),metrics=['acc'])# Start training the modelmodel.fit(x=x_train,y=y_train,validation_data=(x_test,y_test),batch_size=32,epochs=30,callbacks=[PlotLossesKeras()],verbose=1)More ActionsUsing abbreviations to obtain neural networksStarting from version 0.0.2, we can use model aliases to obtain model classes, which are beneficial for simple model
instantiation and reduce code load. Different model abbreviations and instantiation operations are shown below.Original name of the modelModel abbreviationConvNetV1Cnn1ConvNetV2Cnn2ResNetV1RCnn1DenseNetV1Dn1# This is an example Python script.importzWell_modelaszModelfromzWell_model.allModelimportAllModel# Here, the model object of ConvNetV1 was obtained through abbreviation# TODO Cnn1 is an abbreviationz_model:AllModel=zModel.Cnn1(# The number of additional convolutional layers to be added above the specified infrastructure is 4. TODO defaults to 1model_layers_num=4,# Specify the step size in the four convolutional layersstride=[1,2,1,2],# Specify the input dimension of convolutional neural networksinput_shape=(None,32,32,3),# Specify classification quantityclasses=10)print(z_model)print(z_model.to_keras_model())