keras tutorialconda terminal using the below command: spyder To ensure everything was installed correctly, import all the modules, it will add everything and if anything went wrong, you will get module not found Now save your file, restart your terminal and start keras, your backend will be changed. >>> import keras as k using theano backend. Keras 11 Deep learning is an evolving subfield neural networks. A simple sequential model is as follows: from keras.models import Sequential from keras.layers import Dense, Activation model = Sequential() model.add(Dense(512, activation='relu'0 码力 | 98 页 | 1.57 MB | 1 年前3
Keras: 基于 Python 的深度学习库它允许构建任意的神经网络图。 Sequential 顺序模型如下所示: from keras.models import Sequential model = Sequential() 可以简单地使用 .add() 来堆叠模型: KERAS: 基于 PYTHON 的深度学习库 2 from keras.layers import Dense model.add(Dense(units=64, activation='relu' 顺序模型是多个网络层的线性堆叠。 你可以通过将层的列表传递给 Sequential 的构造函数,来创建一个 Sequential 模型: from keras.models import Sequential from keras.layers import Dense, Activation model = Sequential([ Dense(32, input_shape=(784,)), Activation('relu') metrics=['accuracy']) # 均方误差回归问题 model.compile(optimizer='rmsprop', loss='mse') # 自定义评估标准函数 import keras.backend as K def mean_pred(y_true, y_pred): return K.mean(y_pred) model.compile(optimizer='rmsprop'0 码力 | 257 页 | 1.19 MB | 1 年前3
AI大模型千问 qwen 中文文档transformers>=4. 37.0 版本。以下是一个非常简单的代码片段示例,展示如何运行 Qwen1.5-Chat 模型,其中包含 Qwen1. 5-7B-Chat 的实例: from transformers import AutoModelForCausalLM, AutoTokenizer device = "cuda" # the device to load the model onto # Now you modelscope import AutoModelForCausalLM, AutoTokenizer 借助 TextStreamer ,chat 的流式模式变得非常简单。下面我们将展示一个如何使用它的示例: ... # Reuse the code before `model.generate()` in the last code snippet from transformers import TextStreamer about large language models."} ], }' 或者您可以按照下面所示的方式,使用 openai Python 包中的 Python 客户端: from openai import OpenAI # Set OpenAI's API key and API base to use vLLM's API server. openai_api_key = "EMPTY" openai_api_base0 码力 | 56 页 | 835.78 KB | 1 年前3
动手学深度学习 v2.0#@save import collections import hashlib import math import os import random import re import shutil import sys import tarfile import time import zipfile from collections import defaultdict defaultdict import pandas as pd import requests from IPython import display from matplotlib import pyplot as plt from matplotlib_inline import backend_inline d2l = sys.modules[__name__] 本书中的大部分代码都是基于PyT #@save import numpy as np import torch (continues on next page) 目录 5 (continued from previous page) import torchvision from PIL import Image from torch import nn from torch.nn import functional0 码力 | 797 页 | 29.45 MB | 1 年前3
《Efficient Deep Learning Book》[EDL] Chapter 3 - Learning Techniquesdisplaying the results. import numpy as np import cv2 from matplotlib import pyplot as plt from keras.preprocessing.image import ImageDataGenerator from urllib.request import urlopen IMG_SIZE = 224 function takes the name of the dataset and loads the training and the validation splits as follows. import tensorflow_datasets as tfds def make_dataset(name): loadfn = lambda x: tfds.load(name, split=x) resize them to 264x264 size. This is a required step because our model expects fixed-sized images. import tensorflow as tf # Target image size IMG_SIZE = 264 def dsitem_to_tuple(item): return (item['image']0 码力 | 56 页 | 18.93 MB | 1 年前3
机器学习课程-温州大学-Scikit-learn导入工具包 from sklearn import datasets, preprocessing from sklearn.model_selection import train_test_split from sklearn.linear_model import LinearRegression from sklearn.metrics import r2_score 基本建模流程 9 data如S型数据等的生成工具 from sklearn.datasets import load_iris iris = load_iris() X = iris.data y = iris.target 加载数据 10 2.Scikit-learn主要用法 from sklearn.model_selection import train_test_split X_train, X_test 提前打乱数据 数据划分 训练集 测试集 数据集 11 2.Scikit-learn主要用法 使⽤Scikit-learn进⾏数据标准化 from sklearn.preprocessing import StandardScaler 构建转换器实例 scaler = StandardScaler() 拟合及转换 scaler.fit_transform(X_train) 数据预处理 Z-Score标准化0 码力 | 31 页 | 1.18 MB | 1 年前3
《Efficient Deep Learning Book》[EDL] Chapter 7 - Automationsamples, each one assigned to one of the five target classes. import random import tensorflow as tf import numpy as np from tensorflow.keras import layers, losses, optimizers X = tf.random.uniform((20, 5)) and the dataset. import tensorflow as tf import tensorflow_datasets as tfds import keras_tuner as kt import numpy as np from matplotlib import pyplot as plt from tensorflow.keras import applications as as apps from tensorflow.keras import layers, optimizers train_ds, val_ds, test_ds = tfds.load( 'oxford_flowers102', split=['train', 'validation', 'test'], as_supervised=True, read_config=tfds.ReadConf0 码力 | 33 页 | 2.48 MB | 1 年前3
全连接神经网络实战. pytorch 版tensor;矩阵也是张量;多张矩 阵或者多张图像也是张量(3 维张量)。我们在做实验时,可以将 tensor 理解为是“data”。 我们需要先导入 pytorch,顺便导入 numpy: import torch import numpy as np 现在我们尝试将 list 或者 np.array 转换为 pytorch 的数组: data1 = [ [ 1 , 2 ] , [ 3 , 4 ] ] batch_size 数量的样本导出。 注意,前面已经导入过的 python 包我们就不再重复导入了。 from torch . u t i l s . data import Dataset from torch . u t i l s . data import DataLoader 前面说过,Dataset 可以存储自定义数据,我们可以继承 Dataset 类,在子类中实现一些固定 功能的函数,这样就相当于封装了自己的数据为 使用预加载数据,然后第二章就开始构建神经网络模型。等第四章我们再描述如何自定义数据集。 我们一次写一个完整的程序来把数据可视化一下: from torchvision import datasets from torchvision . transforms import ToTensor , Lambda training_data = datasets . FashionMNIST( root=” data ”0 码力 | 29 页 | 1.40 MB | 1 年前3
【PyTorch深度学习-龙龙老师】-测试版202112绍 静态图,以 TensorFlow 1.x 为例,首先创建计算图,代码如下(以下代码需要提前安装 TensorFlow 1.x 框架和 PyTorch 框架,读者可不运行,感受为主): import tensorflow as tf # 导入 TensorFlow 库 # 1.创建计算图阶段,此处代码需要使用 tf 1.x 版本运行 # 创建 2 个输入端子,并指定类型和名字 a_ph 0加法运算尚且如此繁琐,更别说创建复杂 的神经网络算法有多艰难。这种先创建计算图后运行的编程方式叫做符号式编程。 作为对比,现在介绍动态图方式来完成2.0 + 4.0运算。PyTorch 实现代码如下: import torch # 导入 pytorch 库 # 1.创建输入张量,并赋初始值 a = torch.tensor(2.) b = torch.tensor(4.) # 2.直接计算,并打印结果 借助于 PyTorch,可以不需要手动推导导数的表达式,只需要给出函数的表达式,即 可由 PyTorch 自动求导。上式的自动求导代码实现如下: import torch # 导入梯度计算函数 from torch import autograd # 创建 4 个张量 a = torch.tensor(1.) b = torch.tensor(2.) 预览版2021120 码力 | 439 页 | 29.91 MB | 1 年前3
《Efficient Deep Learning Book》[EDL] Chapter 2 - Compression Techniqueslearning and becoming familiar with numpy. # numpy is one of the most useful libraries for ML. import numpy as np def get_scale(x_min, x_max, b): # Compute scale as discussed. return (x_max - x_min image in the form of a 2D matrix having values in [0.0, 1.0]. %matplotlib inline import matplotlib.pyplot as plt import matplotlib.image as mpimg img = (mpimg.imread('pia23378-16.jpg') / 255.0) plt.imshow(img) processed it, we can do some fun stuff with it. import numpy as np import tensorflow as tf import tensorflow.keras as keras from keras.utils import np_utils import tensorflow_datasets as tfds def process_x(x):0 码力 | 33 页 | 1.96 MB | 1 年前3
共 26 条
- 1
- 2
- 3













