train_gen = generator.flow(train_subjects.index, train_targets, shuffle=True) # train_subjects.index for selecting training nodes test_gen = generator.flow(test_subjects.index, test_targets) graphsage_model = GraphSAGE(layer_sizes=[64, 32, 16], generator=generator, aggregator = MaxPoolingAggregator, activations=["relu","relu","linear"], bias=True, dropout=0.1) x_inp, x_out = graphsage_model.in_out_tensors() x_out = get_dropout(x_out, p=0.1, mc='mc') prediction = layers.Dense(units=train_targets.shape[1], activation="relu")(x_out) model_bayesian = Model(inputs=x_inp, outputs=prediction) ##%% ##################################### Model training ####################################################### indices = bf.expandy(batch_size, 2) # def cat_loss(y_true, y_pred): # return tf.keras.losses.categorical_crossentropy( y_true, y_pred, from_logits=False, label_smoothing=0) # @tf.function def noderankloss(): def loss(y_true, y_pred): # tf.print(tf.gather(y_true, tf.constant(index[:, 0]))) index = np.array([[30, 2], [57, 46], [20, 23], [ 7, 27], [26, 2],
# layer_gcnn5 = Reshape((layer_gcnn4.shape[1]*layer_gcnn4.shape[2],))(layer_gcnn4) layer_gcnn5 = Flatten()(layer_gcnn4) # layer_gcnn5 = Dropout(0.2)(layer_gcnn5) # # layer_conv5 = AveragePooling2D(pool_size=(2, 1), strides=None, padding='valid', data_format=None)(layer_conv5) layer_dense1 = Dense(V, activation='linear')(layer_gcnn5) model = Model(inputs=[X_input, graph_conv_filters_input], outputs=layer_dense1) model.summary() # model = cnn_tfmodel.egrmodel2(A, X, graph_conv_filters,2) # simple CNN regression model # model = cnn_tfmodel.cnnmodel2(50) ## loss indices = bf.expandy(V) # def noderankloss_v2(index): # # def loss(y_true, y_pred): # # yt = tf.gather(y_true, index[:, 0], axis=1) - tf.gather(y_true, index[:, 1], axis=1) # yp = tf.gather(y_pred, index[:, 0], axis=1) - tf.gather(y_pred, index[:, 1], axis=1) # # onetensor = tf.ones(shape=tf.shape(yt)) # # zerotensor = tf.zeros(shape= (tf.shape(yt)[0], tf.shape(yt)[0])) # # yp_transpose = tf.transpose(yp) # # part1 = K.dot(onetensor, yp_transpose)