在plot_model中删除绘图背景可以通过设置背景色为透明来实现。具体步骤如下:
from tensorflow.keras.utils import plot_model
import matplotlib.pyplot as plt
model = Sequential()
# 添加模型层
...
model.compile(...)
plot_model(model, to_file='model.png', show_shapes=True, show_layer_names=True)
image = plt.imread('model.png')
plt.imshow(image, alpha=0) # 设置背景色为透明
plt.axis('off') # 关闭坐标轴
plt.savefig('model_transparent.png', bbox_inches='tight', pad_inches=0) # 保存为透明背景的图片
在上述代码中,model.png
是保存的模型图文件名,model_transparent.png
是保存的带有透明背景的模型图文件名。通过设置alpha=0
可以将背景色设置为透明,bbox_inches='tight'
和pad_inches=0
可以去除多余的空白边距。
这样,你就可以得到一个没有绘图背景的模型图了。
没有搜到相关的沙龙