ChatGPT、stable Dissfussion使用教程

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

体验一下之前被刷爆朋友圈的ChatGPT和stable Dissfussion

1 ChatGPT

1.1 chatGPT的注册和使用

1、首先解决上网问题
2、有一个国外的手机用于注册接收短信验证码

解决办法去这个网站申请一个 https://sms-activate.org/
1注册账号
2充值一点点钱
右上角点击充值然后选择支付宝
在这里插入图片描述

在这里插入图片描述
3在左侧选择OpenAI也可以直接搜索OpenAI然后出现很多国家选择一个就可以在这里插入图片描述

在这里插入图片描述

4注册OpenAI账号,
https://beta.openai.com/signup都是些常规的操作会有注册手机号的选择刚刚买到的然后网站上会给出验证码在这里插入图片描述
5进入ChatGPT
https://chat.openai.com/auth/login目前用的人比较多难进入

1.2 使用

在这里插入图片描述

在这里插入图片描述

1.3 尝试一下写代码

手写数字识别数据集
在这里插入图片描述

在这里插入图片描述

import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim

# 加载数据
from torchvision import datasets, transforms

transform = transforms.Compose([transforms.ToTensor(),
                                transforms.Normalize((0.5,), (0.5,))])

trainset = datasets.MNIST('mnist_train', train=True, download=True,
                           transform=transform)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=64, shuffle=True)

testset = datasets.MNIST('mnist_test', train=False, download=True,
                          transform=transform)
testloader = torch.utils.data.DataLoader(testset, batch_size=64, shuffle=True)

# 定义模型
class Net(nn.Module):
    def __init__(self):
        super().__init__()
        self.fc1 = nn.Linear(28 * 28, 128)
        self.fc2 = nn.Linear(128, 64)
        self.fc3 = nn.Linear(64, 10)
        
    def forward(self, x):
        x = x.view(-1, 28 * 28)
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        x = self.fc3(x)
        return x

model = Net()

# 定义损失函数和优化器
criterion = nn.CrossEntropyLoss()
optimizer = optim.SGD(model.parameters(), lr=0.01)

# 训练模型
epochs = 10
for e in range(epochs):
    running_loss = 0
    for images, labels in trainloader:
        optimizer.zero_grad()
        logits = model(images)
        loss = criterion(logits, labels)
        loss.backward()
        optimizer.step()
        
        running_loss += loss.item()
    else:
        print(f"Training loss: {running_loss/len(trainloader)}")

# 测试模型
with torch.no_grad():
    accuracy = 0
    for images, labels in testloader:
        logits = model(images)
        ps = F.softmax(logits, dim=1)
        top_p, top_class = ps.topk(1, dim=1)
        equals = top_class == labels.view(*top_class.shape)
        accuracy += torch.mean(equals.type(torch.FloatTensor))
        
    print(f"Accuracy: {accuracy/len(testloader)}")

感叹ChatGPT的力量真的强。

2、stable-diffusion模型

使用了paddlepaddle的stable-diffusion模型使用autodl平台自己没有好的GPU价格挺便宜的还可以无卡模式写好代码再用卡。https://www.autodl.com

2.1 按照paddlepaddle

!pip install --upgrade paddlepaddle
!pip install --upgrade paddlehub

2.2 画画

from PIL import Image
import paddlehub as hub
 
# 导入模型
module = hub.Module(name='stable_diffusion')
 # A beautiful painting of a singular lighthouse, shining its light across a tumultuous sea of blood by greg rutkowski and thomas kinkade, Trending on artstation
# 生成图像
result = module.generate_image(text_prompts="A beautiful painting by greg rutkowski and thomas kinkade depicts the festive scene of Chinese New Year, where families are decorated with lights and decorations in anticipation of the arrival of the New Year.",style='油画', output_dir='stable_diffusion_out')
    
# 将生成过程存成gif
result[0].chunks[-1].chunks.save_gif('beautiful_painting.gif')

这里text_prompts="A beautiful painting by greg rutkowski and thomas kinkade depicts the festive scene of Chinese New Year, where families are decorated with lights and decorations in anticipation of the arrival of the New Year."写了个春节主题的。

3 结果

在这里插入图片描述

技术进步真是飞速感觉有些行业要被颠覆也有些担忧自己会被替代。继续加油

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: ChatGPT