gongwenxin 2 years ago
parent 77c72f7cd9
commit 55e1ac7653

@ -37,14 +37,50 @@
"state": {
"type": "markdown",
"state": {
"file": "gwx/笔记/第四周 树莓派摄像机推流至上位机人脸检测.md",
"file": "gwx/会议记录/第二次,了解调研方向.md",
"mode": "source",
"source": false
}
}
},
{
"id": "c5f0766b2f9bf20b",
"type": "leaf",
"state": {
"type": "markdown",
"state": {
"file": "gwx/会议记录/2023.2.25.md",
"mode": "source",
"source": false
}
}
},
{
"id": "ed5e742b5e669959",
"type": "leaf",
"state": {
"type": "markdown",
"state": {
"file": "gwx/笔记/第二周,树莓派.md",
"mode": "source",
"source": false
}
}
},
{
"id": "603515a50eabe98e",
"type": "leaf",
"state": {
"type": "markdown",
"state": {
"file": "gwx/会议记录/第三次会议.md",
"mode": "source",
"source": false
}
}
}
],
"currentTab": 2
"currentTab": 5
}
],
"direction": "vertical"
@ -110,7 +146,7 @@
"state": {
"type": "backlink",
"state": {
"file": "gwx/笔记/第四周 树莓派摄像机推流至上位机人脸检测.md",
"file": "gwx/会议记录/第三次会议.md",
"collapseAll": false,
"extraContext": false,
"sortOrder": "alphabetical",
@ -127,7 +163,7 @@
"state": {
"type": "outgoing-link",
"state": {
"file": "gwx/笔记/第四周 树莓派摄像机推流至上位机人脸检测.md",
"file": "gwx/会议记录/第三次会议.md",
"linksCollapsed": false,
"unlinkedCollapsed": true
}
@ -139,7 +175,7 @@
"state": {
"type": "outline",
"state": {
"file": "gwx/笔记/第四周 树莓派摄像机推流至上位机人脸检测.md"
"file": "gwx/会议记录/第三次会议.md"
}
}
},
@ -164,25 +200,25 @@
},
"left-ribbon": {
"hiddenItems": {
"canvas:新建白板": false,
"switcher:打开快速切换": false,
"graph:查看关系图谱": false,
"daily-notes:打开/创建今天的日记": false,
"templates:插入模板": false,
"command-palette:打开命令面板": false,
"canvas:Create new canvas": false
"command-palette:打开命令面板": false
}
},
"active": "623c3f7eeb4b27e5",
"active": "603515a50eabe98e",
"lastOpenFiles": [
"gwx/笔记/第一周,初步使用树莓派.md",
"gwx/会议记录/第一次,认识.md",
"gwx/会议记录/第三次会议.md",
"gwx/会议记录/第二次,了解调研方向.md",
"gwx/笔记/第二周,树莓派.md",
"gwx/笔记/第三周,调研.md",
"gwx/笔记/第四周 树莓派摄像机推流至上位机人脸检测.md",
"gwx/会议记录/第一次,认识.md",
"gwx/会议记录/第三次会议.md",
"gwx/笔记/第一周,初步使用树莓派.md",
"gwx/会议记录/2023.2.25.md",
"孪生/笔记/第三周,调研.md",
"孪生/笔记/第二周,树莓派.md",
"孪生/会议记录/第二次,了解调研方向.md",
"孪生/会议记录/第一次,认识.md"
"孪生/笔记/第二周,树莓派.md"
]
}

@ -1 +1,3 @@
{}
{
"attachmentFolderPath": "./"
}

@ -13,7 +13,7 @@
"state": {
"type": "markdown",
"state": {
"file": "笔记/调研23.3.5.md",
"file": "笔记/唐车会议/焊接问题总结.md",
"mode": "source",
"source": false
}
@ -31,8 +31,7 @@
}
}
}
],
"currentTab": 1
]
}
],
"direction": "vertical"
@ -98,7 +97,7 @@
"state": {
"type": "backlink",
"state": {
"file": "笔记/23.3.16.md",
"file": "笔记/唐车会议/焊接问题总结.md",
"collapseAll": false,
"extraContext": false,
"sortOrder": "alphabetical",
@ -115,7 +114,7 @@
"state": {
"type": "outgoing-link",
"state": {
"file": "笔记/23.3.16.md",
"file": "笔记/唐车会议/焊接问题总结.md",
"linksCollapsed": false,
"unlinkedCollapsed": true
}
@ -138,7 +137,7 @@
"state": {
"type": "outline",
"state": {
"file": "笔记/23.3.16.md"
"file": "笔记/唐车会议/焊接问题总结.md"
}
}
}
@ -159,15 +158,36 @@
"command-palette:打开命令面板": false
}
},
"active": "70e6cb5314947393",
"active": "661f8179ac152cd9",
"lastOpenFiles": [
"笔记/唐车会议/展示/train.py",
"笔记/唐车会议/展示/test.py",
"笔记/唐车会议/展示/pos_time_cvv.csv",
"笔记/唐车会议/展示/origin.csv",
"笔记/唐车会议/展示/line0.csv",
"笔记/唐车会议/展示/line.csv",
"笔记/唐车会议/展示/hyperparameter_optimization.py",
"笔记/唐车会议/展示/hyperparameter.ipynb",
"笔记/唐车会议/展示/guiyi.csv",
"笔记/唐车会议/展示/Figure_1.png",
"笔记/唐车会议/展示/draw.ipynb",
"笔记/唐车会议/展示/delete_same_and_sharp3.csv",
"笔记/唐车会议/Pasted image 20230330202058.png",
"笔记/唐车会议/焊接问题总结.md",
"Pasted image 20230330184328.png",
"会议记录/第一次,认识.md",
"会议记录/attachments/Pasted image 20230203142711.png",
"笔记/attachments/881e413c6a9626ee3775ff1adf1d3ea1_.png",
"笔记/attachments/Pasted image 20230113110339.png",
"笔记/attachments/Pasted image 20230127105516.png",
"笔记/attachments/Pasted image 20230128094700.png",
"笔记/attachments/Pasted image 20230128095432.png",
"笔记/attachments/Pasted image 20230128101901.png",
"笔记/23.3.16.md",
"笔记/调研23.3.5.md",
"会议记录/2023.2.25.md",
"笔记/23.3.16.md",
"笔记/基于LSTM的不完整时序数据填补方法研究_杨建明.caj",
"会议记录/第三次会议.md",
"会议记录/第二次,了解调研方向.md",
"传感器数据.zip",
"笔记/第二周,树莓派.md",
"笔记/第三周,调研.md",
"笔记/第四周 树莓派摄像机推流至上位机人脸检测.md",

File diff suppressed because one or more lines are too long

@ -0,0 +1,142 @@
import matplotlib.pyplot as plt
import numpy as np
import time
from models import MLP
import torch
from torch import nn
import mpldatacursor
time_point = 1
low=0.82
high=0.83
model = MLP.MLP()
model.load_state_dict(torch.load('lstm_model.pt'))
# 创建初始的折线图数据
learning_rate = 0.01
# learning_rate=1
criterion = nn.MSELoss()
# criterion=nn.L1Loss()
optimizer = torch.optim.Adam(model.parameters(), lr=learning_rate)
x = np.array([1])
y = np.array([model.fc0.weight.tolist()[0][0]])
# 绘制初始的折线图
fig, ax = plt.subplots()
line, = ax.plot(x, y, '-o')
# 显示初始的折线图
plt.show(block=False)
# scatter = ax.scatter(x, y)
# # 定义标注文本
# def formatter(**kwargs):
# x, y = kwargs['x'], kwargs['y']
# return f"x={x:.2f}\ny={y:.2f}"
# # 配置悬浮窗
# cursor = mpldatacursor.datacursor(
# scatter,
# formatter=formatter,
# display='multiple',
# draggable=True,
# bbox=dict(fc='white', alpha=0.9),
# arrowprops=dict(arrowstyle='->', connectionstyle='arc3'),
# )
# 定义自定义事件类型
class AddPointEvent:
def __init__(self, x, y):
self.x = x
self.y = y
# 定义事件处理函数,用于处理自定义事件
def on_add_point(event):
# 添加新的点
print(f"x:{event.x},y:{event.y}")
new_x = np.array([event.x])
new_y = np.array([event.y])
# 使用set_xdata()和set_ydata()方法更新折线图的数据
line.set_xdata(np.append(line.get_xdata(), new_x))
line.set_ydata(np.append(line.get_ydata(), new_y))
# 更新折线图的坐标轴范围
ax.relim()
ax.autoscale_view()
ax.annotate("hi", xy=(event.x, event.y), xytext=(event.x, event.y+0.5), ha='center', va='bottom')
# 更新折线图
fig.canvas.draw()
# 连接自定义事件到事件处理函数上
cid = fig.canvas.mpl_connect(AddPointEvent, on_add_point)
# 定义计时器回调函数,用于触发自定义事件
def timer_callback():
# 生成一个随机的点,并触发自定义事件
global time_point
time_point=time_point+1
y=np.random.uniform(low=50, high=101)
y_hat = y*np.random.uniform(low=low, high=high)
batch_sequences = np.array([[y,y_hat]])
# print(batch_sequences.shape)
inputs = torch.tensor(batch_sequences[:, :-1], dtype=torch.float32)
targets = torch.tensor(batch_sequences[:,-1], dtype=torch.float32)
# 前向传播
outputs = model(inputs)
# print(f"targets {targets}")
# print(f"input:{inputs}")
# print(f"outputs {outputs}")
outputs=outputs.reshape(targets.shape)
# print(outputs.shape)
# print(f"output:{outputs.shape}")
# print(f"target:{targets.shape}")
loss = criterion(outputs, targets)
# print(f"loss:{loss}")
# loss=loss*1000
# 反向传播和优化
loss.backward()
optimizer.step()
optimizer.zero_grad()
new_y = model.fc0.weight.tolist()[0][0]
new_event = AddPointEvent(time_point, new_y)
fig.canvas.callbacks.process(AddPointEvent, new_event)
# 重新启动计时器
timer = fig.canvas.new_timer(interval=1000)
timer.add_callback(timer_callback)
timer.start()
# 启动计时器
timer = fig.canvas.new_timer(interval=1000)
timer.add_callback(timer_callback)
timer.start()
def on_hover(event):
# 检查是否有Artist在鼠标位置
if event.inaxes == ax:
# 获取鼠标位置
x, y = event.xdata, event.ydata
# 显示自定义信息
ax.annotate(f'({x:.2f}, {y:.2f})', (x, y))
# 将on_hover函数绑定到Figure的鼠标移动事件上
# fig.canvas.mpl_connect('motion_notify_event', on_hover)
# 显示动态更新的折线图,并保持程序运行
plt.show()

@ -0,0 +1,34 @@
import torch
import torch.nn as nn
import pandas as pd
import numpy as np
from sklearn.preprocessing import MinMaxScaler
input_size = 1
hidden_size = 1
num_layers = 2
output_size = 1
class MLP(nn.Module):
def __init__(self, input_size=1, hidden_size=1, num_layers=2, output_size=1):
super(MLP, self).__init__()
# self.lstm = nn.LSTM(input_size, hidden_size, num_layers, batch_first=True)
# self.lstm = nn.LSTM(input_size, hidden_size, num_layers, batch_first=True)
# self.lstm=nn.RNN(input_size, hidden_size, num_layers, batch_first=True)
self.fc0=nn.Linear(input_size,hidden_size,bias=False)
self.relu = nn.ReLU()
self.fc = nn.Linear(hidden_size, output_size)
nn.init.constant_(self.fc0.weight,0.78)
nn.init.xavier_uniform_(self.fc.weight)
nn.init.zeros_(self.fc.bias)
def forward(self, x):
# out, _ = self.lstm(x)
out0=self.fc0(x)
# out1=self.relu(out0)
# print(f"out{out[0]}")
# print(f"out{out[-1]}")
# out2 = self.fc(out1)
return out0
Loading…
Cancel
Save