https://blog.csdn.net/2301_78630677/article/details/133834096
https://blog.csdn.net/xiaojia1001/article/details/139467176
https://www.kaggle.com/
使用要挂代理,要不然可能无法注册
绑定手机号之后才能使用GPU

 
 
 每周30h免费GPU使用时长
 
上传数据集
Add Input: 添加kaggle平台上已有数据集。
 upload:上传数据集,支持本地压缩文件,也支持指定一个远程的URL来下载


 
 可以直接复制路径
基本使用
查看数据
df = pd.read_csv("/kaggle/input/fashionmnist/fashion-mnist_train.csv")
print(df.shape)
读取前三行数据
print(df.iloc[0:3,:])label  pixel1  pixel2  pixel3  pixel4  pixel5  pixel6  pixel7  pixel8  \
0      2       0       0       0       0       0       0       0       0   
1      9       0       0       0       0       0       0       0       0   
2      6       0       0       0       0       0       0       0       5   pixel9  ...  pixel775  pixel776  pixel777  pixel778  pixel779  pixel780  \
0       0  ...         0         0         0         0         0         0   
1       0  ...         0         0         0         0         0         0   
2       0  ...         0         0         0        30        43         0   pixel781  pixel782  pixel783  pixel784  
0         0         0         0         0  
1         0         0         0         0  
2         0         0         0         0  [3 rows x 785 columns]FashionMnist是一个时装分类的图像数据集,每条数据的第一列为标签分类(0-9),表示10种时装分类。后面784列表示28x28图像展开后每一个像素的值。
使用GPU
import os 
import torchprint(f"cpu nums:{os.cpu_count()}")# 检查是否有可用的 GPU
if torch.cuda.is_available():# 获取 GPU 设备信息for i in range(torch.cuda.device_count()):gpu = torch.cuda.get_device_properties(i)print("GPU {}:".format(i))print("型号:", gpu.name)print("核心数:", gpu.multi_processor_count)  # 核心数print("显存大小:", gpu.total_memory // (1024**2), "MB")  # 显存大小,转换为 MBprint("-----------")
else:print("没有可用的 GPU。")
 GPU主要用来加速pytorch。
 tensorflow,pandas、numpy是不会加速的。
# 创建两个随机张量
a = torch.rand(3, 4)
b = torch.rand(4, 3)# 将张量移动到GPU上
if torch.cuda.is_available():a = a.cuda()b = b.cuda()c = torch.matmul(a, b)print(f"a: {a}")print(f"b: {b}")print(f"c: {c}")
 a、b、c三个矩阵均位于cuda 0号设备上。
 CUDA是NVIDIA提供的一种GPU并行计算框架,在pytorch中使用 .cuda() 表示让我们的模型或者数据从CPU迁移到GPU上(默认是0号GPU),通过GPU开始计算。