From 4a4873339fff4c8ac331311e669158baa9559a3d Mon Sep 17 00:00:00 2001 From: guanjihuan Date: Wed, 29 Nov 2023 00:57:24 +0800 Subject: [PATCH] 0.1.56 --- PyPI/setup.cfg | 2 +- PyPI/src/guan.egg-info/PKG-INFO | 2 +- PyPI/src/guan/machine_learning.py | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/PyPI/setup.cfg b/PyPI/setup.cfg index 6c5fbfe..d591c02 100644 --- a/PyPI/setup.cfg +++ b/PyPI/setup.cfg @@ -1,7 +1,7 @@ [metadata] # replace with your username: name = guan -version = 0.1.55 +version = 0.1.56 author = guanjihuan author_email = guanjihuan@163.com description = An open source python package diff --git a/PyPI/src/guan.egg-info/PKG-INFO b/PyPI/src/guan.egg-info/PKG-INFO index ffdbdf1..a25e587 100644 --- a/PyPI/src/guan.egg-info/PKG-INFO +++ b/PyPI/src/guan.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: guan -Version: 0.1.55 +Version: 0.1.56 Summary: An open source python package Home-page: https://py.guanjihuan.com Author: guanjihuan diff --git a/PyPI/src/guan/machine_learning.py b/PyPI/src/guan/machine_learning.py index d8e4d1b..d16cc16 100644 --- a/PyPI/src/guan/machine_learning.py +++ b/PyPI/src/guan/machine_learning.py @@ -1,13 +1,13 @@ # Module: machine_learning import guan -model_class = None # 把类定义成全局的,防止保存完整模型时,无法访问函数中的类 # 全连接神经网络模型(包含一个隐藏层) @guan.function_decorator def fully_connected_neural_network_with_one_hidden_layer(input_size=1, hidden_size=10, output_size=1, activation='relu'): import torch - global model_class - class model_class(torch.nn.Module): + # 如果在函数中定义模型类,尽量定义成全局的,这样可以防止在保存完整模型到文件时,无法访问函数中的模型类。 + global model_class_of_fully_connected_neural_network_with_one_hidden_layer + class model_class_of_fully_connected_neural_network_with_one_hidden_layer(torch.nn.Module): def __init__(self): super().__init__() self.hidden_layer = torch.nn.Linear(input_size, hidden_size) @@ -25,15 +25,15 @@ def fully_connected_neural_network_with_one_hidden_layer(input_size=1, hidden_si hidden_output = self.hidden_layer(x) output = self.output_layer(hidden_output) return output - model = model_class() + model = model_class_of_fully_connected_neural_network_with_one_hidden_layer() return model # 全连接神经网络模型(包含两个隐藏层) @guan.function_decorator def fully_connected_neural_network_with_two_hidden_layers(input_size=1, hidden_size_1=10, hidden_size_2=10, output_size=1, activation_1='relu', activation_2='relu'): import torch - global model_class - class model_class(torch.nn.Module): + global model_class_of_fully_connected_neural_network_with_two_hidden_layers + class model_class_of_fully_connected_neural_network_with_two_hidden_layers(torch.nn.Module): def __init__(self): super().__init__() self.hidden_layer_1 = torch.nn.Linear(input_size, hidden_size_1) @@ -64,15 +64,15 @@ def fully_connected_neural_network_with_two_hidden_layers(input_size=1, hidden_s output = self.output_layer(hidden_output_2) return output - model = model_class() + model = model_class_of_fully_connected_neural_network_with_two_hidden_layers() return model # 全连接神经网络模型(包含三个隐藏层) @guan.function_decorator def fully_connected_neural_network_with_three_hidden_layers(input_size=1, hidden_size_1=10, hidden_size_2=10, hidden_size_3=10, output_size=1, activation_1='relu', activation_2='relu', activation_3='relu'): import torch - global model_class - class model_class(torch.nn.Module): + global model_class_of_fully_connected_neural_network_with_three_hidden_layers + class model_class_of_fully_connected_neural_network_with_three_hidden_layers(torch.nn.Module): def __init__(self): super().__init__() self.hidden_layer_1 = torch.nn.Linear(input_size, hidden_size_1) @@ -115,7 +115,7 @@ def fully_connected_neural_network_with_three_hidden_layers(input_size=1, hidden output = self.output_layer(hidden_output_3) return output - model = model_class() + model = model_class_of_fully_connected_neural_network_with_three_hidden_layers() return model # 使用优化器训练模型