教程|TensorEditor:一个小白都能快速玩转的神经网络搭建工具
消息来源:baojiabao.com 作者: 发布时间:2026-08-03

机器之心整理
参与:思源
近日,机器之心发现一个非常有意思的工具,可以用可视化的方式轻松添加卷积层、全连接层和池化层等层级,然后生成可执行的 TensorFlow 代码。此外,我们也尝试搭建一个简单的卷捷豹构,并在本地 TensorFlow 环境下测试生成的代码。
工具地址:https://www.tensoreditor.com/
TensorEditor 是一个强大的机器学习工具,甚至小白都能以可视化的方式快速生成整个模型的代码。通过 TensorEditor,小白可以连接卷积层、全连接层和池化层等可视化结点创建整个模型,且我们可以将它们转化为 TensorFlow 和 Python 代码,并进一步在自己的环境中运行。
基本上,TensorEditor 的步骤即定义我们的数据集、图像或特征,然后创建深度神经网络并下载 Python 2.7 的代码,最后就需要在我们自己的 TensorFLow 环境下运行就好了。
通过 TensorEditor,我们不仅可以创建深度网络并避免一些常见的代码问题,同时还能生成基于 TensorFlow Estimator 的高效代码。如下所示,机器之心尝试构建了一个简单的卷积网络,我们使用了两个卷积层、两个池化层和一个全连接层,并在最后的 Estimator 使用了交叉熵损失函数和 Adagrad 最优化方法。
上述简单搭建的卷积网络同样可以生成完全可执行的代码,这样可以避免大量的一般代码问题与重复性工作。
import
tensorflow as tf
import
pandas as pd
tf
.
logging
.
set_verbosity
(
tf
.
logging
.
INFO
)
project_name
=
"CNN"
train_csv_file
=
""
test_csv_file
=
""
image_resize
=[
28
,
28
]
def model_fn
(
features
,
labels
,
mode
,
params
):
convolutional_2d_1
=
tf
.
layers
.
conv2d
(
inputs
=
features
,
filters
=
32
,
kernel_size
=[
3
,
3
],
strides
=(
1
,
1
),
padding
=
"same"
,
data_format
=
"channels_last"
,
dilation_rate
=(
1
,
1
),
activation
=
tf
.
nn
.
relu
,
use_bias
=
True
)
max_pool_2d_1
=
tf
.
layers
.
max_pooling2d
(
inputs
=
convolutional_2d_1
,
pool_size
=[
2
,
2
],
strides
=[
2
,
2
],
padding
=
"same"
,
data_format
=
"channels_last"
)
convolutional_2d_2
=
tf
.
layers
.
conv2d
(
inputs
=
max_pool_2d_1
,
filters
=
64
,
kernel_size
=[
3
,
3
],
strides
=(
1
,
1
),
padding
=
"same"
,
data_format
=
"channels_last"
,
dilation_rate
=(
1
,
1
),
activation
=
tf
.
nn
.
relu
,
use_bias
=
True
)
max_pool_2d_2
=
tf
.
layers
.
max_pooling2d
(
inputs
=
max_pool_2d_1
,
pool_size
=[
2
,
2
],
strides
=[
2
,
2
],
padding
=
"same"
,
data_format
=
"channels_last"
)
convolutional_2d_3
=
tf
.
layers
.
conv2d
(
inputs
=
max_pool_2d_2
,
filters
=
128
,
kernel_size
=[
3
,
3
],
strides
=(
1
,
1
),
padding
=
"same"
,
data_format
=
"channels_last"
,
dilation_rate
=(
1
,
1
),
activation
=
tf
.
nn
.
relu
,
use_bias
=
True
)
max_pool_2d_3
=
tf
.
layers
.
max_pooling2d
(
inputs
=
convolutional_2d_3
,
pool_size
=[
2
,
2
],
strides
=[
2
,
2
],
padding
=
"same"
,
data_format
=
"channels_last"
)
flatten_1
=
tf
.
reshape
(
max_pool_2d_3
,
[-
1
,
2048
])
dense_1
=
tf
.
layers
.
dense
(
inputs
=
flatten_1
,
units
=
1024
,
activation
=
tf
.
nn
.
relu
)
dropout_1
=
tf
.
layers
.
dropout
(
inputs
=
dense_1
,
rate
=
0.4
,
training
=
mode
==
tf
.
estimator
.
ModeKeys
.
TRAIN
)
dense_2
=
tf
.
layers
.
dense
(
inputs
=
dropout_1
,
units
=
256
,
activation
=
tf
.
nn
.
relu
)
logits
=
dense_2
predictions
=
{
"classes"
:
tf
.
argmax
(
input
=
logits
,
axis
=
1
),
"probabilities"
:
tf
.
nn
.
softmax
(
logits
,
name
=
"softmax_tensor"
)
}
#
Prediction
and training
if
mode
==
tf
.
estimator
.
ModeKeys
.
PREDICT
:
return
tf
.
estimator
.
EstimatorSpec
(
mode
=
mode
,
predictions
=
predictions
)
#
Calculate
Loss
(
for
both TRAIN and EVAL modes
)
onehot_labels
=
tf
.
one_hot
(
indices
=
tf
.
cast
(
labels
,
tf
.
int32
),
depth
=
256
)
loss
=
tf
.
losses
.
softmax_cross_entropy
(
onehot_labels
=
onehot_labels
,
logits
=
logits
)
#
Compute
evaluation metrics
.
accuracy
=
tf
.
metrics
.
accuracy
(
labels
=
labels
,
predictions
=
predictions
[
"classes"
],
name
=
"acc_op"
)
metrics
=
{
"accuracy"
:
accuracy
}
tf
.
summary
.
scalar
(
"accuracy"
,
accuracy
[
1
])
#
Configure
the
Training
Op
(
for
TRAIN mode
)
if
mode
==
tf
.
estimator
.
ModeKeys
.
TRAIN
:
optimizer
=
tf
.
train
.
AdagradOptimizer
(
learning_rate
=
0.001
)
train_op
=
optimizer
.
minimize
(
loss
=
loss
,
global_step
=
tf
.
train
.
get_global_step
())
return
tf
.
estimator
.
EstimatorSpec
(
mode
=
mode
,
loss
=
loss
,
train_op
=
train_op
)
#
Add
evaluation metrics
(
for
EVAL mode
)
eval_metric_ops
=
{
"accuracy"
:
tf
.
metrics
.
accuracy
(
labels
=
labels
,
predictions
=
predictions
[
"classes"
])}
return
tf
.
estimator
.
EstimatorSpec
(
mode
=
mode
,
loss
=
loss
,
eval_metric_ops
=
eval_metric_ops
)
#
Parse
CSV input file and resize image
def _parse_csv
(
line
):
parsed_line
=
tf
.
decode_csv
(
line
,
[[
""
],
[]])
filename
=
parsed_line
[
0
]
label
=
parsed_line
[
1
]
image_string
=
tf
.
read_file
(
filename
)
image_decoded
=
tf
.
image
.
decode_jpeg
(
image_string
,
channels
=
3
)
image_resized
=
tf
.
image
.
resize_images
(
image_decoded
,
image_resize
)
image_gray
=
tf
.
image
.
rgb_to_grayscale
(
image_resized
)
return
image_gray
,
label
def data_train_estimator
():
dataset
=
tf
.
data
.
TextLineDataset
(
train_csv_file
).
map
(
_parse_csv
)
#
Map
each line to convert the data
dataset
=
dataset
.
batch
(
100
)
dataset
=
dataset
.
shuffle
(
1000
)
dataset
=
dataset
.
repeat
()
iterator
=
dataset
.
make_one_shot_iterator
()
#
create one shot iterator
feature
,
label
=
iterator
.
get_next
()
return
feature
,
label
def data_test_estimator
():
dataset
=
tf
.
data
.
TextLineDataset
(
test_csv_file
).
map
(
_parse_csv
)
#
Map
each line to convert the data
dataset
=
dataset
.
batch
(
100
)
iterator
=
dataset
.
make_one_shot_iterator
()
#
create one shot iterator
feature
,
label
=
iterator
.
get_next
()
return
feature
,
label
def main
(
unused_argv
):
#
MAIN ENTRY
#
Create
the
Estimator
classifier
=
tf
.
estimator
.
Estimator
(
model_fn
=
model_fn
,
model_dir
=
"/tmp/"
+
project_name
,
params
={
#
PARAMS
}
)
classifier
.
train
(
input_fn
=
data_train_estimator
,
steps
=
30000
)
eval_results
=
classifier
.
evaluate
(
input_fn
=
data_test_estimator
)
tf
.
summary
.
scalar
(
"Accuracy"
,
eval_results
[
"accuracy"
])
print
(
eval_results
)
if
__name__
==
"__main__"
:
tf
.
app
.
run
()
TensorEditor 主要有以下特点:
易于使用:我们只需要添加模块、连接模块并在最后加入评估模块,就能完成搭建。
由易到难:只需要叠加不同的模块,我们就能创建如 VGG 那样的复杂深度网络。
参数直观:可以轻松修改各结点的配置与参数,从而搭建定制化的深度网络。
生成代码:搭建完深度架构,我们就能直接生成可执行的 TensorFlow 代码(Python 2.7)。
90 秒的 MNIST 教程
最后上面的网络就能生成对应的代码,我们可直接复制到本地代码编辑器中并执行:
本文为机器之心整理,
转载请联系本公众号获得授权
。?------------------------------------------------
加入机器之心(全职记者/实习生):hr@jiqizhixin.com
投稿或寻求报道:
content
@jiqizhixin.com广告&商务合作:bd@jiqizhixin.com
相关文章
B站怎么炸崩了哔哩哔哩服务器今日怎么又炸挂了?技术团队公开早先原因2023-03-06 19:05:55
苹果iPhoneXS/XR手机电池容量续航最强?答案揭晓2023-02-19 15:09:54
华为荣耀两款机型起内讧:荣耀Play官方价格同价同配该如何选?2023-02-17 23:21:27
google谷歌原生系统Pixel3 XL/4/5/6 pro手机价格:刘海屏设计顶配版曾卖6900元2023-02-17 18:58:09
科大讯飞同传同声翻译软件造假 浮夸不能只罚酒三杯2023-02-17 18:46:15
华为mate20pro系列手机首发上市日期价格,屏幕和电池参数配置对比2023-02-17 18:42:49
小米MAX4手机上市日期首发价格 骁龙720打造大屏标准2023-02-17 18:37:22
武汉弘芯遣散!结局是总投资1280亿项目烂尾 光刻机抵押换钱2023-02-16 15:53:18
谷歌GoogleDrive网云盘下载改名“GoogleOne” 容量提升价格优惠2023-02-16 13:34:45
巴斯夫将裁员6000人 众化工巨头裁员潮再度引发关注2023-02-13 16:49:06
人手不足 韵达快递客服回应大量包裹派送异常没有收到2023-02-07 15:25:20
资本微念与李子柒销声匿迹谁赢? 微念公司退出子柒文化股东2023-02-02 09:24:38
三星GalaxyS8 S9 S10系统恢复出厂设置一直卡在正在检查更新怎么办2023-01-24 10:10:02
华为Mate50 RS保时捷最新款顶级手机2022多少钱?1.2万元售价外观图片吊打iPhone142023-01-06 20:27:09
芯片常见的CPU芯片封装方式 QFP和QFN封装的区别?2022-12-02 17:25:17
华为暂缓招聘停止社招了吗?官方回应来了2022-11-19 11:53:50
热血江湖手游:长枪铁甲 刚猛热血 正派枪客全攻略技能介绍大全2022-11-16 16:59:09
东京把玩了尼康微单相机Z7 尼康Z7现在卖多少钱?2022-10-22 15:21:55
苹果iPhone手机灵动岛大热:安卓灵动岛App应用下载安装量超100万次2022-10-03 22:13:45
苹果美版iPhone可以在中国保修 从哪看怎么查询iPhone的生产日期?2022-09-22 10:00:07










