def train(n_iterations):
    raw = gp.ArrayKey('RAW')
    gt = gp.ArrayKey('GT')
    gt_fg = gp.ArrayKey('GT_FP')
    embedding = gp.ArrayKey('EMBEDDING')
    fg = gp.ArrayKey('FG')
    maxima = gp.ArrayKey('MAXIMA')
    gradient_embedding = gp.ArrayKey('GRADIENT_EMBEDDING')
    gradient_fg = gp.ArrayKey('GRADIENT_FG')
    emst = gp.ArrayKey('EMST')
    edges_u = gp.ArrayKey('EDGES_U')
    edges_v = gp.ArrayKey('EDGES_V')
    request = gp.BatchRequest()
    request.add(raw, (200, 200))
    request.add(gt, (160, 160))
    snapshot_request = gp.BatchRequest()
    snapshot_request[embedding] = request[gt]
    snapshot_request[fg] = request[gt]
    snapshot_request[gt_fg] = request[gt]
    snapshot_request[maxima] = request[gt]
    snapshot_request[gradient_embedding] = request[gt]
    snapshot_request[gradient_fg] = request[gt]
    snapshot_request[emst] = gp.ArraySpec()
    snapshot_request[edges_u] = gp.ArraySpec()
    snapshot_request[edges_v] = gp.ArraySpec()
    pipeline = (((Synthetic2DSource(raw, gt) + gp.Normalize(raw)) + gp.tensorflow.Train('train_net', optimizer=add_loss, loss=None, inputs={tensor_names['raw']: raw, tensor_names['gt_labels']: gt}, outputs={tensor_names['embedding']: embedding, tensor_names['fg']: fg, 'maxima:0': maxima, 'gt_fg:0': gt_fg, emst_name: emst, edges_u_name: edges_u, edges_v_name: edges_v}, gradients={tensor_names['embedding']: gradient_embedding, tensor_names['fg']: gradient_fg})) + gp.Snapshot(output_filename='{iteration}.hdf', dataset_names={raw: 'volumes/raw', gt: 'volumes/gt', embedding: 'volumes/embedding', fg: 'volumes/fg', maxima: 'volumes/maxima', gt_fg: 'volumes/gt_fg', gradient_embedding: 'volumes/gradient_embedding', gradient_fg: 'volumes/gradient_fg', emst: 'emst', edges_u: 'edges_u', edges_v: 'edges_v'}, dataset_dtypes={maxima: np.float32, gt_fg: np.float32}, every=100, additional_request=snapshot_request))
    with gp.build(pipeline):
        for i in range(n_iterations):
            pipeline.request_batch(request)
def train(n_iterations):
    raw = gp.ArrayKey('RAW')
    gt = gp.ArrayKey('GT')
    gt_fg = gp.ArrayKey('GT_FP')
    embedding = gp.ArrayKey('EMBEDDING')
    fg = gp.ArrayKey('FG')
    maxima = gp.ArrayKey('MAXIMA')
    gradient_embedding = gp.ArrayKey('GRADIENT_EMBEDDING')
    gradient_fg = gp.ArrayKey('GRADIENT_FG')
    emst = gp.ArrayKey('EMST')
    edges_u = gp.ArrayKey('EDGES_U')
    edges_v = gp.ArrayKey('EDGES_V')
    request = gp.BatchRequest()
    request.add(raw, (200, 200))
    request.add(gt, (160, 160))
    snapshot_request = gp.BatchRequest()
    snapshot_request[embedding] = request[gt]
    snapshot_request[fg] = request[gt]
    snapshot_request[gt_fg] = request[gt]
    snapshot_request[maxima] = request[gt]
    snapshot_request[gradient_embedding] = request[gt]
    snapshot_request[gradient_fg] = request[gt]
    snapshot_request[emst] = gp.ArraySpec()
    snapshot_request[edges_u] = gp.ArraySpec()
    snapshot_request[edges_v] = gp.ArraySpec()
    pipeline = (((Synthetic2DSource(raw, gt) + gp.Normalize(raw)) + gp.tensorflow.Train('train_net', optimizer=add_loss, loss=None, inputs={tensor_names['raw']: raw, tensor_names['gt_labels']: gt}, outputs={tensor_names['embedding']: embedding, tensor_names['fg']: fg, 'maxima:0': maxima, 'gt_fg:0': gt_fg, emst_name: emst, edges_u_name: edges_u, edges_v_name: edges_v}, gradients={tensor_names['embedding']: gradient_embedding, tensor_names['fg']: gradient_fg})) + gp.Snapshot(output_filename='{iteration}.hdf', dataset_names={raw: 'volumes/raw', gt: 'volumes/gt', embedding: 'volumes/embedding', fg: 'volumes/fg', maxima: 'volumes/maxima', gt_fg: 'volumes/gt_fg', gradient_embedding: 'volumes/gradient_embedding', gradient_fg: 'volumes/gradient_fg', emst: 'emst', edges_u: 'edges_u', edges_v: 'edges_v'}, dataset_dtypes={maxima: np.float32, gt_fg: np.float32}, every=100, additional_request=snapshot_request))
    with gp.build(pipeline):
        for i in range(n_iterations):
            pipeline.request_batch(request)