1.2MBZIP
[Description of resources]
基于HAM10000数据集实现皮肤癌分类python源码+使用说明.zip
这是一个用于训练图像分类模型的代码。在运行代码之前,用户需要安装以下依赖库:argparse, os, pandas, numpy, PIL, datasets, torchvision, tqdm和transformers。用户还需要从Hugging Face上下载所需的预训练模型。
参数说明
– `–metadata_path`:metadata文件的路径。默认为”./archive/HAM10000_metadata.csv”。
– `–images_dir`:图像文件夹的路径。默认为”./archive/HAM10000_images/”。
– `–model_dir`:预训练模型的路径。默认为”../model/vit-large-patch16-224-in21k”。
– `–checkpoints_dir`:保存检查点文件的文件夹路径。默认为”./checkpoints”。
– `–learning_rate`:学习率。默认为1e-5。
– `–batch_size`:批大小。默认为64。
– `–epochs`:训练轮数。默认为5。
– `–warmup_ratio`:预热步骤的比例。默认为0.1。
– `–split`:训练-验证数据集的分割比例。默认为0.8。
– `–gpu`:指定使用哪张GPU。默认为”0″。
– `–logging_steps`:每隔多少步记录一次训练日志。默认为50。
用户可以在命令行中传递这些参数,例如:
"`shell
python train-hf.py –metadata_path ./archive/HAM4000_metadata.csv \
–images_dir ./archive/HAM10000_images/ \
–checkpoints_dir ./checkpoints \
–learning_rate 1e-4 \
–batch_size 64 \
–epochs 20 \
–warmup_ratio 0.1 \
–model_dir ../model/vit-large-patch16-224-in21k \
–gpu 5,6,7 \
–logging_steps 1
“`
在代码运行过程中,会执行以下步骤:
1. 读取metadata文件,获取图像文件名和标签。
2. 将图像读入内存,并随机打乱。
3. 将数据集划分为训练集和验证集。
4. 对图像进行预处理,包括随机裁剪、归一化和转换为tensor。
5. 加载预训练模型,构建分类器。
6. 训练模型,并在验证集上评估模型性能。
7. 在训练过程中,每隔logging_steps步记录一次训练日志,包括损失值、准确率等指标。
8. 在训练结束后,保存模型的权重文件到checkpoints_dir文件夹中。
[Remarks]
该项目是个人毕设/课设/大作业项目,代码都经过本地调试测试,功能ok才上传,高分作品,可快速上手运行!欢迎下载使用,可用于小白学习、进阶。
This resource is mainly for students, teachers or practitioners of computer, communication, artificial intelligence, automation and other related majors to download and use, and can also be used as the final course design, course work, graduation design, etc..
The project as a whole has a high learning value! Strong basic ability can be modified and adjusted on this basis to achieve different functions.
欢迎下载使用,也欢迎交流学习!
Resource Disclaimer (Purchase is deemed to be agreement with this statement): 1. Any operation on the website platform is considered to have read and agreed to the registration agreement and disclaimer at the bottom of the website, this site resources have been ultra-low price, and does not provide technical support 2. Some network users share the net disk address may be invalid, such as the occurrence of failure, please send an e-mail to customer service code711cn#qq.com (# replaced by @) will be made up to send 3. This site provides all downloadable resources (software, etc.) site to ensure that no negative changes; but this site can not guarantee the accuracy, security and integrity of the resources, the user downloads at their own discretion, we communicate to learn for the purpose of not all the source code is not 100% error-free or no bugs; you need to have a certain foundation to be able to read and understand the code, be able to modify the debugging yourself! code and solve the error. At the same time, users of this site must understand that the Source Code Convenience Store does not own any rights to the software provided for download, the copyright belongs to the legal owner of the resource. 4. All resources on this site only for learning and research purposes, please must be deleted within 24 hours of the downloaded resources, do not use for commercial purposes, otherwise the legal disputes arising from the site and the publisher of the collateral liability site and will not be borne! 5. Due to the reproducible nature of the resources, once purchased are non-refundable, the recharge balance is also non-refundable