Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if type(self.model_def) is str:
input_size = (X.shape[-1],)
self.model_, anchor_embedding, _, _ = \
triplet_network(base_network(self.model_def, input_size),
embedding_dims=self.embedding_dims)
else:
self.model_, anchor_embedding, _, _ = \
triplet_network(self.model_def,
embedding_dims=self.embedding_dims)
if Y is None:
self.model_.compile(optimizer='adam', loss=triplet_loss_func)
else:
if is_categorical(self.supervision_metric):
if not is_multiclass(self.supervision_metric):
if not is_hinge(self.supervision_metric):
# Binary logistic classifier
if len(Y.shape) > 1:
self.n_classes = Y.shape[-1]
else:
self.n_classes = 1
supervised_output = Dense(self.n_classes, activation='sigmoid',
name='supervised')(anchor_embedding)
else:
# Binary Linear SVM output
if len(Y.shape) > 1:
self.n_classes = Y.shape[-1]
else:
self.n_classes = 1
supervised_output = Dense(self.n_classes, activation='linear',
name='supervised',
kernel_regularizer=regularizers.l2())(anchor_embedding)
self.n_classes = Y.shape[-1]
else:
self.n_classes = 1
supervised_output = Dense(self.n_classes, activation='sigmoid',
name='supervised')(anchor_embedding)
else:
# Binary Linear SVM output
if len(Y.shape) > 1:
self.n_classes = Y.shape[-1]
else:
self.n_classes = 1
supervised_output = Dense(self.n_classes, activation='linear',
name='supervised',
kernel_regularizer=regularizers.l2())(anchor_embedding)
else:
if not is_hinge(self.supervision_metric):
validate_sparse_labels(Y)
self.n_classes = len(np.unique(Y[Y != np.array(-1)]))
# Softmax classifier
supervised_output = Dense(self.n_classes, activation='softmax',
name='supervised')(anchor_embedding)
else:
self.n_classes = len(np.unique(Y, axis=0))
# Multiclass Linear SVM output
supervised_output = Dense(self.n_classes, activation='linear',
name='supervised',
kernel_regularizer=regularizers.l2())(anchor_embedding)
else:
# Regression
if len(Y.shape) > 1:
self.n_classes = Y.shape[-1]
else: