摘要:
from torchvision.datasets import MNIST # import torchvision # torchvision.datasets. #准备数据集 mnist = MNIST(root="./mnist",train=True,download=True) prin 阅读全文
摘要:
import torch from torch.utils.data import Dataset,DataLoader class SmsDataset(Dataset): def __init__(self): self.file_path = "./SMSSpamCollection" sel 阅读全文
摘要:
实验代码 import torch import torch.nn as nn #y = wx + b class MyModel(nn.Module): def __init__(self): super(MyModel,self).__init__() #自定义代码 # self.w = tor 阅读全文
摘要:
import torch import matplotlib.pyplot as plt learning_rate = 0.1 #准备数据 #y = 3x +0.8 x = torch.randn([500,1]) y_true = 3*x + 0.8 #计算预测值 w = torch.rand( 阅读全文
摘要:
前项计算1 import torch # (3*(x+2)^2)/4 #grad_fn 保留计算的过程 x = torch.ones([2,2],requires_grad=True) print(x) y = x+2 print(y) z = 3*y.pow(2) print(z) out = z 阅读全文
摘要:
import torch import numpy as np device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") x = torch.tensor(np.arange(15).reshape(3,5)) i 阅读全文
摘要:
import torch import numpy as np a = torch.tensor([[[1]]]) #只有一个数据的时候,获取其数值 print(a.item()) #tensor转化为nparray b = a.numpy() print(b,type(b),type(a)) #获 阅读全文
摘要:
import torch import numpy as np print(torch.tensor([1,2,3])) print(torch.tensor(np.arange(15).reshape(3,5))) print(torch.empty([3,4])) print(torch.one 阅读全文
摘要:
数据的读取 import tensorflow as tf from tensorflow.python import keras from tensorflow.python.keras.preprocessing.image import ImageDataGenerator class Tra 阅读全文
摘要:
from tensorflow.python.keras.applications.vgg16 import VGG16,preprocess_input,decode_predictions from tensorflow.python.keras.preprocessing.image impo 阅读全文