tensorflow tf flops计算

https://pypi.org/project/keras-flops/

from tensorflow.keras import Model, Input
from tensorflow.keras.layers import Dense, Flatten, Conv2D, MaxPooling2D, Dropout

from keras_flops import get_flops
# build model

# build model
# inp = Input((32, 32, 1))
# x = Conv2D(32, kernel_size=(3, 3), activation="relu")(inp)
# x = MaxPooling2D(pool_size=(2, 2))(x)
# x = Flatten()(x)
# x = Dense(128, activation="relu")(x)
# out = Dense(10, activation="softmax")(x)
# model = Model(inp, out)

# # build model
# build model
inp = Input((32, 32, 1))
x = Conv2D(32, 3, padding='same', activation='relu')(inp)
#x = Conv2D(64, (3, 3), activation="relu")(x)
x = MaxPooling2D(pool_size=(2, 2))(x)
x = Dropout(0.25)(x)
x = Flatten()(x)
x = Dense(128, activation="relu")(x)
x = Dropout(0.5)(x)
out = Dense(10, activation="softmax")(x)
model = Model(inp, out)
model.summary()
# calculae flops
flops = get_flops(model, batch_size=1)
print(f"flops: {flops / 10 ** 9:.03} g")

结果
_TFProfRoot (–/2.76m flops)
functional_1/dense/MatMul (2.10m/2.10m flops)
functional_1/conv2d/Conv2D (589.82k/589.82k flops)
functional_1/conv2d/BiasAdd (32.77k/32.77k flops)
functional_1/max_pooling2d/MaxPool (32.77k/32.77k flops)
functional_1/dense_1/MatMul (2.56k/2.56k flops)
functional_1/dense/BiasAdd (128/128 flops)
functional_1/dense_1/Softmax (50/50 flops)
functional_1/dense_1/BiasAdd (10/10 flops)
End of Report====
flops: 0.00276 g

  • 5
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值