Open lidefan888 opened 3 months ago
请问你解决了么?我在/data/projects/fate/fate/python/fate_llm/model_zoo添加effnet.py(应该是你的efficientnet_net)后报另一个错误ValueError: Did not find any class in effnet.py that is subclass of nn.Module and named effnet. Do you mean EfficientNet?' 但是我/data/projects/fate/fate/python/federatedml/nn/model_zoo中有effnet.py和它引用的原型efficientnet.py
请问大佬们,我的FATE版本是1.11.3,使用自定义模型时一直报错 ModuleNotFoundError: No module named 'fate_llm',请问如何解决呢 本地测试通过了
以下是我的运行代码 from federatedml.nn.dataset.image import ImageDataset from federatedml.nn.model_zoo.image_net import ImgNet from federatedml.nn.model_zoo.efficientnet_net import EfficientNet from federatedml.nn.dataset.mnist_dataset import MNISTDataset
ds = MNISTDataset() ds.load("/data/projects/fate/mnist/")
import torch as t from federatedml.nn.homo.trainer.fedavg_trainer import FedAVGTrainer
class Args: def init( self, basic_model_architecture="efficientnet-b0", pretrained_model_path="/data/projects/fate/efficientnet-b0.pth", ): self.basic_model_architecture = basic_model_architecture self.pretrained_model_path = pretrained_model_path
img_model = model = EfficientNet.from_pretrained(Args(), num_classes=10, in_channels=3) trainer = FedAVGTrainer( epochs=3, batch_size=4, shuffle=True, data_loader_worker=2, pin_memory=False )
print(img_model) trainer.set_model(img_model) # set model
trainer.local_mode() # !! use local mode to skip federation process !!
optimizer = t.optim.Adam(img_model.parameters(), lr=0.01) loss = t.nn.CrossEntropyLoss()
import torch as t from torch import nn from pipeline import fate_torch_hook from pipeline.component import HomoNN from pipeline.backend.pipeline import PipeLine from pipeline.component import Reader, Evaluation, DataTransform from pipeline.interface import Data, Model
t = fate_torch_hook(t)
import os
host = 10000 guest = 9999 arbiter = 10000 pipeline = ( PipeLine() .set_initiator(role="guest", party_id=guest) .set_roles(guest=guest, host=host, arbiter=arbiter) )
data_0 = {"name": "mnist_guest", "namespace": "experiment"} data_1 = {"name": "mnist_host", "namespace": "experiment"}
data_path_0 = "/data/projects/fate/mnist" data_path_1 = "/data/projects/fate/mnist" pipeline.bind_table( name=data_0["name"], namespace=data_0["namespace"], path=data_path_0 ) pipeline.bind_table( name=data_1["name"], namespace=data_1["namespace"], path=data_path_1 )
reader_0 = Reader(name="reader_0") reader_0.get_party_instance(role="guest", party_id=guest).component_param(table=data_0) reader_0.get_party_instance(role="host", party_id=host).component_param(table=data_1)
from pipeline.component.homo_nn import DatasetParam, TrainerParam
model = t.nn.Sequential( t.nn.CustModel(module_name="efficientnet_net", class_name="EfficientNet", class_num=10) )
nn_component = HomoNN( name="nn_0", model=model, # your cust model loss=t.nn.CrossEntropyLoss(), optimizer=t.optim.Adam(model.parameters(), lr=0.01), dataset=DatasetParam(dataset_name="image"), # use image dataset trainer=TrainerParam( trainer_name="fedavg_trainer", epochs=3, batch_size=1024, validation_freqs=1 ), torch_seed=100, # global random seed )
pipeline.add_component(reader_0) pipeline.add_component(nn_component, data=Data(train_data=reader_0.output.data)) pipeline.add_component( Evaluation(name="eval_0", eval_type="multi"), data=Data(data=nn_component.output.data), )
pipeline.compile() pipeline.fit()