- 博客(482)
- 收藏
- 关注
原创 Python3画等高线 (有代码)
可以根据提供的数据生成等高线,并根据等高线下的区域填充不同的颜色。该函数通常用于可视化二维数据集的密度分布或二维函数的等高线图。它接受三个参数:X, Y 和 Z,其中X和Y分布是二维数据集中的x坐标和y坐标,Z是对应的数据值。要画等高线,需要用到。
2024-03-28 23:08:12 46
原创 机器学习 - 创建一个PyTorch classification model
先得将数据从 numpy arrays 移到 PyTorch tensor 里。需要创建 loss function 和 optimizer。设置 loss function 和 Optimizer。之后,将数据分成训练集和测试集。都看到这了,给个赞呗~
2024-03-26 00:14:27 849
原创 机器学习 - save和load训练好的模型
是一个用于序列化和反序列化Python对象的标准库模块。它可以将Python对象转换为字节流 (即序列化),并将字节流转换回Python对象 (即反序列化)。在深度学习中,经常需要保存训练好的模型或者训练过程中的中间结果,以便后续的使用或分析。PyTorch提高了方便的API来保存和加载模型,其中就包括了使用。模块在很多情况下都非常有用,特别是在保存和加载模型,保存训练中间状态等方面。如果已经训练好了一个模型,你就可以save和load这模型。模块进行对象的序列化和反序列化。
2024-03-20 17:31:06 476
原创 机器学习 - 预测训练模型
torch.inference.mode() 是一个上下文管理器,用于控制推断模式下的模型行为。在深度学习中,模型在训练和推断 (或称为预测) 阶段有不同的行为。在推断阶段,通常不需要计算梯度,也不需要跟踪计算图,这样可以提高推断速度并减少内存占用。这样可以确保模型在推断阶段不会意外地计算梯度,提高了推断的速度和效率。上下文环境时,PyTorch会关闭梯度跟踪,并且禁用自动微分机制。在下图,能看到预测点跟测试点很靠近,这结果挺理想的。上下文管理器就是为了控制模型在推断阶段的行为。
2024-03-20 12:19:17 554
原创 机器学习 - 训练模型
它是梯度下降算法的变种,在每次更新参数时都使用随机样本的梯度估计来更新参数。在每次迭代中,SGD随机选择一小批样本 (mini-batch) 来计算损失函数关于参数的梯度,并使用该梯度来更新参数。Adam优化器是一种常用的优化算法,它结合了动量法和自适应学习率调整的特性,能够高效地优化神经网络模型的参数。而自适应学习率调整项可以根据参数的历史梯度来调整学习率,从而在不同参数上使用不同的学习率,使得参数更新更加稳健。MAE计算的是预测值与真实值之间的绝对差值的平均值,即平均误差的绝对值。
2024-03-19 16:28:49 1188
原创 机器学习 - 选择模型
Neural Network Block的设计旨在简化神经网络模型的构建和管理,提高代码的可读性和可维护性。通过将神经网络模型划分为多个块,可以将模型的不同部分进行分离,使得每个部分都可以独立地设计,调整和复用。这种模块化的设计使得构建复杂的神经网络变得更加灵活和高效。Neural Network Block 通常指的是神经网络中的一个模块化组件,它可以包含一个或多个层 (layers) 以及一些额外的操作,被设计用来完成特定的功能或实现特定的神经网络结构。比如:卷积神经网络中的卷积块。
2024-03-19 12:18:10 837
原创 机器学习 - 准备数据
下面是代码展示,创建一个straight line data。将上面获取到的数据进行拆分,每部分数据带有不同的意思。通过将各个数字显示出来,更直观。机器学习其实可以分为两部分。都看到这了,给个赞呗~
2024-03-18 23:13:46 647
原创 机器学习 - PyTorch使用流程
标准的 PyTorch Workflow 是这样的. But the workflow steps can be repeated and changed depending on the problem you’re working on.看到这了,给个赞呗~
2024-03-17 23:33:25 529
原创 机器学习 - Reproducibility
的方法来操作,其中的device是 target device you’d like the tensor (or model) to go to.如果想将tensor back to CPU来使用numpy,可以使用。如果想要将tensor放到GPU上运行,可以通过。如果通过添加seed,两个Tensor就一样了。这里稍微提一下CUDA。看到这了,给个赞呗~
2024-03-17 18:12:22 358
原创 机器学习 - PyTorch tensor 和 numpy
因为numpy是一个python numerical computing library, PyTorch 可以 interact with it nicely.下面是代码来展示,让tensor和numpy做两者之间的互相转换。
2024-03-17 12:56:20 540
原创 机器学习 - Indexing 使用
有时候,你需要从tensor里取出特定的数据,这就得用到 indexing 的方法了。获取index对应的位置。
2024-03-17 11:36:30 830
原创 机器学习 - PyTorch里的aggregation
在PyTorch里,可以在tensor里找到min, max, mean, sum 等aggregation值。偶尔我们要将tensor的维度进行reshape, stack, squeeze, and unsqueeze。在深度学习中,会经常出现的问题是tensor的数据类型不对。如果一个tensor的数据类型是。可以在tensor里找到最大值和最小值的位置,用到。其中的 dtype 参数是你想用的数据类型。要改变tensor的数据类型,可以使用。,而另一个tensor的数据类型是。,运行起来就出错了。
2024-03-16 18:54:12 619
原创 机器学习 - 线性问题
模块也被称为 “feed-forward layer"或者"fully connected layer”。矩阵做 transpose。
2024-03-16 00:06:17 457
原创 机器学习 - PyTorch 常见的操作
在 PyTorch 里,可以使用 torch.matmul() 方法。可以用PyTorch做加减乘除操作。都看到这里了,给个赞咯~
2024-03-15 17:57:27 482
原创 机器学习 - PyTorch一些常用的用法
在 PyTorch 中,精度 (precision) 值通常情况下,精度值可以是8, 16, 32或64,分别对应unit8, 单精度浮点数 (float32),半精度浮点数 (float16), 双精度浮点数 (float64)。英伟达的GPUs用了computing toolkit,这个toolkit叫做 CUDA。想创建一个有范围的tensor,就得需要用到 torch.arange()有时候需要通过加入数字0和数字1到tensor里。要想创建一个全部都是0或者是1的tensor。
2024-03-15 15:08:11 557
原创 机器学习 - PyTorch中常使用到的名字解释
下面是python的例子,最基本的向量表示方式是使用列表或数组来存储数据。举个例子: 你可以来描述一张image。
2024-03-14 18:26:20 491
原创 机器学习 - Python导入外部的代码到本地
如果我们发现在某平台发现这代码文件挺有用的,可以通过Python代码将其下载。就可以看到在文件夹里已经将example.py文件下载下来了。
2024-03-14 14:00:08 309
原创 机器学习 - 手动实现交叉验证法
交叉验证法 (cross validation): 将数据集D划分成 k 个大小相同或者相似的互斥的子集,每次使用 k - 1 个子集的并集作为训练集,剩余的子集作为测试集,进行k次训练和测试,计算模型在测试集上的准确率,最终返回k个测试结果的平均值 (k 最常用的取值是10)代码如下:结果:都看到这,点个赞支持一下咯~
2024-03-05 15:02:00 345
原创 机器学习 -测试集和训练集的划分
下面是用代码来实现这两种方法,用到的数据集是 Iris Dataset。这里记录在机器学习中,使用几种方法来做对数据集进行拆分成。库中的 sklearn.datasets 的模块。
2024-03-03 23:29:57 396
原创 Identity and Authentication - Sending Tokens with Requests
先给个简单代码来热热身from flask import Flask, requestapp = Flask(__name__)@app.route('/headers')def headers(): # unpack the request header print('hello world') return 'not implemented'在 Terminal里,对应的文件夹里,输入下面的命令$ export FLASK_APP=example.py$ ex
2022-01-17 06:48:00 1122 1
原创 Identity and Authentication - Local Storage
Local Storage is an implementation of a key-value store which is accessible through a javascript interface in most modern browsers. It is a general purpose interface to store strings which will persist in memory from session to session. It is designed for
2022-01-16 14:38:42 234
原创 Identity and Authentication - 验证 Autho0 Tokens (附代码)
如何使用jwt, 请点击这里查看如何使用 Authorization, 点击这里在这里,就放一个简单的代码import sysimport json# pip3 install python-josefrom jose import jwtfrom urllib.request import urlopen# Configuration# UPDATE THIS TO REFLECT YOUR AUTH0 ACCOUNTAUTH0_DOMAIN = 'YOUR_AUTH0_DOMAIN
2022-01-16 14:03:23 348
原创 Identity and Authentication - Generating and Verifying JWTs (附代码)
如果要了解 jwt, 点击这里简单代码实现import jwtimport base64# Init our Datapayload = { 'school':'example'}algo = 'HS256'secret = 'learning'# Encode a JWTencoded_jwt = jwt.encode(payload, secret, algorithm=algo)print(encoded_jwt)# Decode a JWTdecoded_jw
2022-01-16 13:05:00 2149
原创 Identity and Authentication - JSO Web Tokens (JWTs)
使用 JWTs 的好处:StatelessDifficult to FakePopular and easily implemented across platformsFlexbileParts of a JSON Web Tokenheader.payload.signatureIncluding Data in Our JWT Payload解释 Payload:{ "user":"usr", "school":"example", "role": "rle"}
2022-01-16 12:39:08 2647
原创 Identity and Authentication - Implementing Auth0 (实现Auth0)
点击这里,进入设置Auth0如果还没有账号,就sign up,创建一个账号。就按照下面的步骤来实现Autho0根据图片里的指示操作在 Settings 里创建 Application URIs其他选项,保持default setting, 在最后点击 save changesApplications 设置好之后,就得设置 APIs在 Setting里,保持default settings.用这个例子来判断,设置有没有成功复制 highlight 部分,到 C
2022-01-16 12:02:56 325
原创 Identity and Authentication - Implementing Auth0
第三方验证图The front-end interact with a third party service to provide the login screen, and perform the authentication. The software will direct our clients to a hosted page provided by Auth0. On this page, the user can perform one of many types of authenti
2022-01-16 08:28:06 181
原创 Identity and Authentication - Third Party Auth Systems
Third Party Auth SystemsMost of the risk lies in our back-end, where the user is making a request, our server is attempting to find our ground truth, and determining whether or not that user is who they say they are.MonolithicOften in monolithic serv
2022-01-16 07:56:03 302
原创 Identity and Authentication - Alternative Authentication Methods
Single Sign-on (SSO)The Single Sign-on or trusting someone else to answer the question who is making the request? Single Sign-on gives us a bunch of benefits. First, we don’t have to perform the actual authentication. We’re trusting that some engineers at
2022-01-16 07:36:58 206
原创 Identity and Authentication - Common Authentication Methods
Username and PasswordsThis is the most common method of identifying users in the age of Software as a Service (SaaS)解释上面的图中的步骤:Login Request:POST /loginpostuser = { username: 'users', password: 'pws'}Find users:SELECT * FROM database_exampleWH
2022-01-16 07:10:45 3396
原创 Identity and Authentication - 介绍
Token is a temporary credential that can be stored on our client and be sent along with each future request. When the server receives a token, we verify that token is valid, we can perform specific actions that might be sensitive and return a response to .
2022-01-16 06:52:03 200
原创 Identity and Access Management - python decorators (代码)
from functools import wraps def add_greeting(f): @wraps(f) def wrapper(*args, **kwargs): print("Hello!") return f(*args, **kwargs) return wrapper@add_greetingdef print_name(name): print(name)print_name('sandy')结果如下:
2022-01-07 09:18:19 481 1
原创 Identity and Access Management - 复习HTTP和Flask (代码)
文件结构example| example.py# example.pyfrom flask import Flask, request, jsonify, abort app = Flask(__name__)greetings = { 'en': 'hello', 'es': 'Hola', 'ar': 'مرحبا', 'ru': 'Привет', 'fi': 'Hei', 'he': 'שלום', 'ja': 'こんにち
2022-01-07 08:44:48 854
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人