当前位置:网站首页>[Over 17] Pytorch rewrites keras
[Over 17] Pytorch rewrites keras
2022-08-05 05:26:00 【Mosu playing computer】
任务
pytorchBuild your own modelkeras
想法
- 有pytorchself-built model code
- can be found line by linekerasreplace it with the corresponding layer(手工转写
- Pytorch转keras的有效方法,以FlowNet为例_咆哮的阿杰的博客-CSDN博客_pytorch转keras
- tensorflow和keras_手动 pytorch 模型转 tensorflow keras 模型_weixin_39637920的博客-CSDN博客
There are self-built models exportedonnx,作为中间件可以onnx转keras(自动转- 搞不出来
查到的博客
首先,We must have a clear understanding,网上以及githubSome of the so-called abovepytorch转换Keras或者Keras转换成PytorchThe tool code is almost inoperable or has limitations of use(For example, only certain models can be converted),But we can see some clues in these conversion codes,For example, the size of the parameters of the two(shape)的形式、channel的排序(first or last)是否一样,Master the difference,You can write your own conversion code based on these differences,没错,Write the conversion code yourself,是最稳妥的办法.The whole process is divided into two parts.The author will use Nvidia开源的FlowNet为例,将开源的Pytorch代码转化为Keras模型.
按照Pytorch中模型的结构,编写对应的Keras代码,用keras的函数式API,It would be very convenient to build.
把Pytorch的模型参数,Assigned to in order according to the name of the layerKeras的模型
Although the above two steps seem simple,But in reality, I also took a lot of detours.A key point here,就是参数的shapeIs it unified in the two frameworks,That is of course not uniform.查到的博客
pytorch 到 tensorflow 可以用onnxConvert as an intermediate tool,将pytorch转为onnx,再从onnx转为tensorflow,But there may be some messy problems in the middle.In fact, it is also very convenient to manually read the parameters and refill the corresponding model,This article summarizes manual model conversion.
过程
I would definitely try it first 自动转
pytorch模型转keras模型_AI算法-图哥的博客-CSDN博客_pytorch2keras
ONNX系列二 — 使用ONNX使KerasModels are portable_Igloo's blog-CSDN博客_keras onnx
安装一下
接触到了(load和load_state_dict)的问题
Pytorch保存和加载模型(load和load_state_dict)_木盏的博客-CSDN博客_pytorch 加载模型
插曲
安装whl
真是服了,onnx1.8.1It was later removedoptimizer那个包,然后pytorch2kerasThis package uses the version is1.8.1及之前的,onnx1.8.1支持py3.8,然后我Py3.9.So had to be in another virtual environment(py3.6)Reinstalled the corresponding package inside(400M的tensorflow还有torch等等).安好了,Thought it could be used now
然后报 modulelist的错
Then I export as onnx,再load,就报“TypeError: ‘ModelProto’ object is not callable”的错
我真是服了.
It seems that it can only be written by hand
python关于onnx模型的一些基本操作_A glass of salt water blog-CSDN博客_onnx 静态量化
学习keras,主要是 The parameters on both sides are different
It's better to change.(不问对错,就是搭积木)
结果
input_data = keras.layers.Input(shape=(4,1), dtype='float64')
cnn_out = keras.layers.Conv1D(1, kernel_size=2, strides=1)(input_data)
cnn_out = keras.layers.MaxPool1D(2)(cnn_out)
lstm_out =keras.layers.LSTM(4)(cnn_out)
dense_out = keras.layers.Dense(3,activation='softmax')(lstm_out)
model = keras.Model(input_data, dense_out)
model.compile(optimizer='adam',loss='mean_absolute_error',metrics=['accuracy'])
model.summary()
The rewrite was successful,But what about the accuracy,very rubbish
边栏推荐
- A blog clears the Redis technology stack
- 【过一下8】全连接神经网络 视频 笔记
- 【过一下7】全连接神经网络视频第一节的笔记
- 浅谈Servlet生命周期
- redis cache clearing strategy
- CAP+BASE
- Community Sharing|Tencent Overseas Games builds game security operation capabilities based on JumpServer
- HQL语句执行过程
- LeetCode: 1403. Minimum subsequence in non-increasing order [greedy]
- coppercam primer [6]
猜你喜欢
Difference between for..in and for..of
拿出接口数组对象中的所有name值,取出同一个值
Detailed Explanation of Redis Sentinel Mode Configuration File
Flink EventTime和Watermarks案例分析
解决端口占用问题
[Go through 7] Notes from the first section of the fully connected neural network video
vscode要安装的插件
[Study Notes Dish Dog Learning C] Classic Written Exam Questions of Dynamic Memory Management
The difference between the operators and logical operators
[Go through 9] Convolution
随机推荐
The difference between the operators and logical operators
Xiaobai, you big bulls are lightly abused
怎么更改el-table-column的边框线
Multi-threaded query results, add List collection
机器学习(二) —— 机器学习基础
el-table鼠标移入表格改变显示背景色
[Go through 3] Convolution & Image Noise & Edge & Texture
[Software Exam System Architect] Software Architecture Design ③ Domain-Specific Software Architecture (DSSA)
redis cache clearing strategy
Flink EventTime和Watermarks案例分析
Pycharm中使用pip安装第三方库安装失败:“Non-zero exit code (2)“的解决方法
Flink HA配置
2022 The 4th C.Easy Counting Problem (EGF+NTT)
SQL(二) —— join窗口函数视图
【技能】长期更新
【过一下3】卷积&图像噪音&边缘&纹理
数据库 单表查询
第四讲 back propagation 反向传播
[Go through 4] 09-10_Classic network analysis
对数据排序