TF-GNN踩坑记录
Posted LoveFishO
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TF-GNN踩坑记录相关的知识,希望对你有一定的参考价值。
引言
由于图数据结构问题,直接使用Tensorflow
的一些层是无法直接处理图数据的,需要借用TF-GNN
框架下的MapFeatures
对图数据中的节点特征或是边特征进行变换。
题外话(MapFeatures使用)
节点特征变换
from tensorflow.keras.layers import BatchNormalization
from tensorflow_gnn.keras.layers import MapFeatures
# map node features
def node_sets_fn(node_set, *, node_set_name):
features = node_set.features
return BatchNormalization()(features["hidden_state"])
graph = MapFeatures(node_sets_fn=node_sets_fn)(graph)
边特征变换
from tensorflow_gnn.keras.layers import MapFeatures
# Hashes edge features called "id", leaves others unchanged:
def edge_sets_fn(edge_set, *, edge_set_name):
features = edge_set.get_features_dict()
ids = features.pop("id")
num_bins = 100_000 if edge_set_name == "views" else 20_000
hashed_ids = tf.keras.layers.Hashing(num_bins=num_bins)(ids)
features["hashed_id"] = hashed_ids
return features
graph = MapFeatures(edge_sets_fn=edge_sets_fn)(graph)
传入额外参数
from functools import partial
from tensorflow.keras.layers import Dense
from tensorflow_gnn.keras.layers import MapFeatures
# map node features
def node_sets_fn(node_set, *, node_set_name, dim):
features = node_set.features
return Dense(dim)(features["hidden_state"])
graph = MapFeatures(node_sets_fn=partial(node_sets_fn, dim=64))(graph)
问题
就是在使用MapFeatures
时,如果循环使用则会在存储模型的时候报错:ValueError: Unable to create dataset (name already exists)
问题demo
from functools import partial
from tensorflow.keras.layers import Dense
from tensorflow_gnn.keras.layers import MapFeatures
# map node features
def node_sets_fn(node_set, *, node_set_name, dim):
features = node_set.features
return Dense(dim)(features["hidden_state"])
for ln in range(layer_num):
graph = MapFeatures(node_sets_fn=partial(node_sets_fn, dim=64))(graph)
解决方案
最后发现是在使用MapFeatures
时,使用层时如Dense
需要区分每一次变换时的层名
from functools import partial
from tensorflow.keras.layers import Dense
from tensorflow_gnn.keras.layers import MapFeatures
# map node features
def node_sets_fn(node_set, *, node_set_name, dim,name):
features = node_set.features
return Dense(dim, name=f\'Dense_name\')(features["hidden_state"])
for ln in range(layer_num):
graph = MapFeatures(node_sets_fn=partial(node_sets_fn, dim=64,name=ln))(graph)
本文来自博客园,作者:LoveFishO,转载请注明原文链接:https://www.cnblogs.com/lovefisho/p/17355084.html
Kubernetes踩坑记录
参考技术A 到目前为止,我们已经在使用K8s集群建设上积累了一年多的经验。在此期间,我们也踩了很多坑,现在我把一些典型的问题记录下来,便于大家避坑。通过kubeadm安装K8s时,默认的pod子网如下图所示,这就导致K8s集群内最多只能加入256台机器,并且10.xxx.xxx.xxx 不太好与内网IP段区分,建议修改成172.xxx.xxx.xxx。
需要修改pod子网配置为:
kube-flannel初始设置的cpu和内存都比较小,容易出现OOMKilled,所以要增大cpu和内存设置。
待补充
待补充
使用Kubeadm搭建Kubernetes(1.13.1)集群
kubeadm搭建高可用K8s集群
以上是关于TF-GNN踩坑记录的主要内容,如果未能解决你的问题,请参考以下文章