Git Product home page Git Product logo

Comments (10)

BAAI-OpenPlatform avatar BAAI-OpenPlatform commented on August 27, 2024

Inference参考这里:https://github.com/FlagAI-Open/FlagAI/blob/master/examples/AltCLIP/altclip_inference.py
可以用如下的代码加载模型权重
model_save_path = "xxx"
model.load_state_dict(torch.load(model_save_path, map_location="cuda")["module"])

from flagai.

yanchaoguo avatar yanchaoguo commented on August 27, 2024

Inference参考这里:https://github.com/FlagAI-Open/FlagAI/blob/master/examples/AltCLIP/altclip_inference.py 可以用如下的代码加载模型权重 model_save_path = "xxx" model.load_state_dict(torch.load(model_save_path, map_location="cuda")["module"])

@BAAI-OpenPlatform train 的时候可以使用valid_dataset进行metric_methods计算吗 如下是否可执行
trainer.train(model=model, train_dataset = dl, valid_dataset=vdl, metric_methods=[["top1_acc", "top5_acc"]], optimizer = torch.optim.SGD(model.parameters(), lr=1e-3))

from flagai.

BAAI-OpenPlatform avatar BAAI-OpenPlatform commented on August 27, 2024

AltCLIP的evaluation可以参考https://github.com/FlagAI-Open/FlagAI/blob/master/examples/AltCLIP/AltCLIP_evaluation.py
其他模型的evaluation一般来说是这样子的:

可以在Trainer初始化的时候添加一行 eval_interval=10,
from flagai.methics import accuracy_metric
然后trainer.train()里插入:metric_method=[("accuracy", accuracy_metric)]

from flagai.

yanchaoguo avatar yanchaoguo commented on August 27, 2024

AltCLIP的evaluation可以参考https://github.com/FlagAI-Open/FlagAI/blob/master/examples/AltCLIP/AltCLIP_evaluation.py 其他模型的evaluation一般来说是这样子的:

可以在Trainer初始化的时候添加一行 eval_interval=10, from flagai.methics import accuracy_metric 然后trainer.train()里插入:metric_method=[("accuracy", accuracy_metric)]

@BAAI-OpenPlatform 有错误
│ C:\Users\bigdata\AppData\Roaming\Python\Python38\site-packages\flagai\trainer.py:1108 in │
│ evaluate_and_print_results │
│ │
│ 1105 │ ): │
│ 1106 │ │ """Helper function to evaluate and dump results on screen.""" │
│ 1107 │ │ │
│ ❱ 1108 │ │ eval_dict = self.evaluate(forward_step_func=forward_step_func, │
│ 1109 │ │ │ │ │ │ │ │ data_loader=data_loader, │
│ 1110 │ │ │ │ │ │ │ │ model=model, │
│ 1111 │ │ │ │ │ │ │ │ verbose=verbose) │
│ │
│ C:\Users\bigdata\AppData\Roaming\Python\Python38\site-packages\flagai\trainer.py:971 in evaluate │
│ │
│ 968 │ │ # Turn on evaluation mode which disables dropout. │
│ 969 │ │ tmp_model.eval() │
│ 970 │ │ if hasattr(tmp_model, │
│ ❱ 971 │ │ │ │ 'config') and 'checkpoint_activations' in tmp_model.config: │
│ 972 │ │ │ tmp_checkpoint_activations = tmp_model.config[ │
│ 973 │ │ │ │ 'checkpoint_activations'] │
│ 974 │ │ │ tmp_model.config['checkpoint_activations'] = False │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: argument of type 'AltCLIPConfig' is not iterable

下面代码是我的trainer:
trainer = Trainer(env_type="pytorch",
pytorch_device=device,
experiment_name="clip_finetuning",
batch_size=batch_size,
lr=1e-4,
epochs=20,
fp16=True,
eval_interval=10,
log_interval=50)
trainer.train(model=model, train_dataset = dl, valid_dataset=vdl, metric_methods=[("accuracy", accuracy_metric)], optimizer = torch.optim.SGD(model.parameters(), lr=1e-3))

from flagai.

920232796 avatar 920232796 commented on August 27, 2024

AltCLIP的evaluation可以参考https://github.com/FlagAI-Open/FlagAI/blob/master/examples/AltCLIP/AltCLIP_evaluation.py 其他模型的evaluation一般来说是这样子的:
可以在Trainer初始化的时候添加一行 eval_interval=10, from flagai.methics import accuracy_metric 然后trainer.train()里插入:metric_method=[("accuracy", accuracy_metric)]

@BAAI-OpenPlatform 有错误 │ C:\Users\bigdata\AppData\Roaming\Python\Python38\site-packages\flagai\trainer.py:1108 in │ │ evaluate_and_print_results │ │ │ │ 1105 │ ): │ │ 1106 │ │ """Helper function to evaluate and dump results on screen.""" │ │ 1107 │ │ │ │ ❱ 1108 │ │ eval_dict = self.evaluate(forward_step_func=forward_step_func, │ │ 1109 │ │ │ │ │ │ │ │ data_loader=data_loader, │ │ 1110 │ │ │ │ │ │ │ │ model=model, │ │ 1111 │ │ │ │ │ │ │ │ verbose=verbose) │ │ │ │ C:\Users\bigdata\AppData\Roaming\Python\Python38\site-packages\flagai\trainer.py:971 in evaluate │ │ │ │ 968 │ │ # Turn on evaluation mode which disables dropout. │ │ 969 │ │ tmp_model.eval() │ │ 970 │ │ if hasattr(tmp_model, │ │ ❱ 971 │ │ │ │ 'config') and 'checkpoint_activations' in tmp_model.config: │ │ 972 │ │ │ tmp_checkpoint_activations = tmp_model.config[ │ │ 973 │ │ │ │ 'checkpoint_activations'] │ │ 974 │ │ │ tmp_model.config['checkpoint_activations'] = False │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ TypeError: argument of type 'AltCLIPConfig' is not iterable

下面代码是我的trainer: trainer = Trainer(env_type="pytorch", pytorch_device=device, experiment_name="clip_finetuning", batch_size=batch_size, lr=1e-4, epochs=20, fp16=True, eval_interval=10, log_interval=50) trainer.train(model=model, train_dataset = dl, valid_dataset=vdl, metric_methods=[("accuracy", accuracy_metric)], optimizer = torch.optim.SGD(model.parameters(), lr=1e-3))

您好,能否发一下accuracy_metric这个函数?

from flagai.

yanchaoguo avatar yanchaoguo commented on August 27, 2024

AltCLIP的evaluation可以参考https://github.com/FlagAI-Open/FlagAI/blob/master/examples/AltCLIP/AltCLIP_evaluation.py 其他模型的evaluation一般来说是这样子的:
可以在Trainer初始化的时候添加一行 eval_interval=10, from flagai.methics import accuracy_metric 然后trainer.train()里插入:metric_method=[("accuracy", accuracy_metric)]

@BAAI-OpenPlatform 有错误 │ C:\Users\bigdata\AppData\Roaming\Python\Python38\site-packages\flagai\trainer.py:1108 in │ │ evaluate_and_print_results │ │ │ │ 1105 │ ): │ │ 1106 │ │ """Helper function to evaluate and dump results on screen.""" │ │ 1107 │ │ │ │ ❱ 1108 │ │ eval_dict = self.evaluate(forward_step_func=forward_step_func, │ │ 1109 │ │ │ │ │ │ │ │ data_loader=data_loader, │ │ 1110 │ │ │ │ │ │ │ │ model=model, │ │ 1111 │ │ │ │ │ │ │ │ verbose=verbose) │ │ │ │ C:\Users\bigdata\AppData\Roaming\Python\Python38\site-packages\flagai\trainer.py:971 in evaluate │ │ │ │ 968 │ │ # Turn on evaluation mode which disables dropout. │ │ 969 │ │ tmp_model.eval() │ │ 970 │ │ if hasattr(tmp_model, │ │ ❱ 971 │ │ │ │ 'config') and 'checkpoint_activations' in tmp_model.config: │ │ 972 │ │ │ tmp_checkpoint_activations = tmp_model.config[ │ │ 973 │ │ │ │ 'checkpoint_activations'] │ │ 974 │ │ │ tmp_model.config['checkpoint_activations'] = False │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ TypeError: argument of type 'AltCLIPConfig' is not iterable
下面代码是我的trainer: trainer = Trainer(env_type="pytorch", pytorch_device=device, experiment_name="clip_finetuning", batch_size=batch_size, lr=1e-4, epochs=20, fp16=True, eval_interval=10, log_interval=50) trainer.train(model=model, train_dataset = dl, valid_dataset=vdl, metric_methods=[("accuracy", accuracy_metric)], optimizer = torch.optim.SGD(model.parameters(), lr=1e-3))

您好,能否发一下accuracy_metric这个函数?

from flagai.metrics import accuracy_metric

我这边把 train里的验证集去掉 换成下面的形式就可以运行了
trainer.train(model=model, train_dataset = dl, metric_methods=[("accuracy", accuracy_metric)], optimizer = torch.optim.SGD(model.parameters(), lr=1e-3))
我的验证集和训练集的构建方式是一样的 只是取了不同范围的数据 @920232796

from flagai.

yanchaoguo avatar yanchaoguo commented on August 27, 2024

@BAAI-OpenPlatform 关于使用altcllip训练自己的数据集 能给一个带metric_methods的例子吗

from flagai.

920232796 avatar 920232796 commented on August 27, 2024

@BAAI-OpenPlatform 关于使用altcllip训练自己的数据集 能给一个带metric_methods的例子吗

一般这种任务的话,验证是可以选择另外的一个数据集,而且针对不同数据集类型,分为分类和检索,不同数据集类型的验证方式也不一样,这里推荐您可以尝试一下分类的,比较简单,例如可以选择CIFAR-10,CIFAR-100,或者Imagenet的验证集。具体代码您可以看一下examples/AltCLIP/AltCLIP_evaluation.py 。

如果您使用相同的数据集,那么应该就是检索类(图文),这块您可以参考这个代码进行修改:https://github.com/LAION-AI/CLIP_benchmark/blob/main/clip_benchmark/metrics/zeroshot_retrieval.py

from flagai.

yanchaoguo avatar yanchaoguo commented on August 27, 2024

@BAAI-OpenPlatform 关于使用altcllip训练自己的数据集 能给一个带metric_methods的例子吗

一般这种任务的话,验证是可以选择另外的一个数据集,而且针对不同数据集类型,分为分类和检索,不同数据集类型的验证方式也不一样,这里推荐您可以尝试一下分类的,比较简单,例如可以选择CIFAR-10,CIFAR-100,或者Imagenet的验证集。具体代码您可以看一下examples/AltCLIP/AltCLIP_evaluation.py 。

如果您使用相同的数据集,那么应该就是检索类(图文),这块您可以参考这个代码进行修改:https://github.com/LAION-AI/CLIP_benchmark/blob/main/clip_benchmark/metrics/zeroshot_retrieval.py

我这边训练数据用的是自己整理的图/文数据 ,并没有对应的label ,这种情况下 我在train方法里 如何指定 验证数据集 以及如何 选择metric_methods

from flagai.

920232796 avatar 920232796 commented on August 27, 2024

可以的,你这个数据就是相当于我说的retrieval,labels应该就是图像对应的文本吧,然后其他图像当作负样本,所以train函数中,传入val_dataset以后,metric_methods需要参考我发给您的那个retrieval代码来写。

from flagai.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.