Beispiel #1
0
        public static NDArrayList SplitAndLoad(NDArray data, Context[] ctx_list, int batch_axis = 0,
                                               bool even_split = true)
        {
            if (ctx_list.Length == 1)
            {
                return(data.AsInContext(ctx_list[0]));
            }

            var slices = SplitData(data, ctx_list.Length, batch_axis, even_split);

            var result = new NDArrayList();

            result = slices.Zip(ctx_list, (i, ctx) => { return(i.AsInContext(ctx)); }).ToList();

            return(result.ToArray());
        }
Beispiel #2
0
        public override void Update(NDArray labels, NDArray preds)
        {
            float loss = 0;
            var   num  = 0;

            labels = labels.AsInContext(preds.Context).Reshape(preds.Size);
            preds  = nd.Pick(preds, labels.AsType(DType.Int32), Axis);
            if (IgnoreLabel.HasValue)
            {
                var ignore = nd.EqualScalar(labels, IgnoreLabel.Value).AsType(preds.DataType);
                num  -= nd.Sum(ignore).AsScalar <int>();
                preds = preds * (1 - ignore) + ignore;
            }

            loss -= nd.Sum(nd.Log(nd.MaximumScalar(preds, 1e-10f))).AsScalar <float>();
            num  += preds.Size;

            sum_metric        += loss;
            global_sum_metric += loss;
            num_inst          += num;
            global_num_inst   += num;
        }
Beispiel #3
0
 internal virtual NDArray MaskTransform(NDArray mask)
 {
     return(mask.AsInContext(mx.Cpu()).AsType(DType.Int32));
 }
Beispiel #4
0
 internal NDArray ImgTransform(NDArray img)
 {
     return(img.AsInContext(mx.Cpu()));
 }