Ejemplo n.º 1
0
        public ILayer CreateProduct(IKernelDescriptor descriptor)
        {
            if (descriptor is AvgPooling1D)
            {
                AvgPooling1D pool = descriptor as AvgPooling1D;

                ILayer layer = new AvgPool1DLayer(pool.Padding, pool.Stride, pool.KernelSize);

                return(layer);
            }

            return(null);
        }
Ejemplo n.º 2
0
        private List <IKernelDescriptor> ReadDescriptors(JObject model)
        {
            List <IKernelDescriptor> dscps = model.SelectToken("descriptors").Select(layer => {
                IKernelDescriptor descriptor = null;

                String layerName = (String)layer.SelectToken("layer");

                switch (layerName)
                {
                case "AvgPooling1D":
                    descriptor = new AvgPooling1D(
                        (int)layer.SelectToken("padding"),
                        (int)layer.SelectToken("stride"),
                        (int)layer.SelectToken("kernel_size"));
                    break;

                case "GlobalAveragePooling1D":
                    descriptor = new GlobalAvgPooling1D();
                    break;

                case "AvgPooling2D":
                    descriptor = new AvgPooling2D((int)layer.SelectToken("padding_vl"), (int)layer.SelectToken("padding_hz"),
                                                  (int)layer.SelectToken("stride_vl"), (int)layer.SelectToken("stride_hz"),
                                                  (int)layer.SelectToken("kernel_height"), (int)layer.SelectToken("kernel_width"));
                    break;

                case "GlobalAveragePooling2D":
                    descriptor = new GlobalAvgPooling2D();
                    break;

                case "BatchNormalization":
                    descriptor = new BatchNormalization(
                        (int)layer.SelectToken("epsilon"));
                    break;

                case "Cropping1D":
                    descriptor = new Cropping1D(
                        (int)layer.SelectToken("trimBegin"),
                        (int)layer.SelectToken("trimEnd"));
                    break;

                case "Cropping2D":
                    descriptor = new Cropping2D(
                        (int)layer.SelectToken("topTrim"),
                        (int)layer.SelectToken("bottomTrim"),
                        (int)layer.SelectToken("leftTrim"),
                        (int)layer.SelectToken("rightTrim"));
                    break;

                case "MaxPooling1D":
                    descriptor = new MaxPooling1D(
                        (int)layer.SelectToken("padding"),
                        (int)layer.SelectToken("stride"),
                        (int)layer.SelectToken("kernel_size"));
                    break;

                case "GlobalMaxPooling1D":
                    descriptor = new GlobalMaxPooling1D();
                    break;

                case "MaxPooling2D":
                    descriptor = new MaxPooling2D((int)layer.SelectToken("padding_vl"), (int)layer.SelectToken("padding_hz"),
                                                  (int)layer.SelectToken("stride_vl"), (int)layer.SelectToken("stride_hz"),
                                                  (int)layer.SelectToken("kernel_height"), (int)layer.SelectToken("kernel_width"));
                    break;

                case "GlobalMaxPooling2D":
                    descriptor = new GlobalMaxPooling2D();
                    break;

                case "Convolution1D":
                    descriptor = new Convolution1D(
                        (int)layer.SelectToken("padding"),
                        (int)layer.SelectToken("stride"),
                        (int)layer.SelectToken("kernel_size"),
                        (int)layer.SelectToken("kernel_num"));
                    break;

                case "Convolution2D":
                    descriptor = new Convolution2D((int)layer.SelectToken("padding_vl"), (int)layer.SelectToken("padding_hz"),
                                                   (int)layer.SelectToken("stride_vl"), (int)layer.SelectToken("stride_hz"),
                                                   (int)layer.SelectToken("kernel_height"), (int)layer.SelectToken("kernel_width"),
                                                   (int)layer.SelectToken("kernel_num"));
                    break;

                case "Dense2D":
                    descriptor = new Dense2D((int)layer.SelectToken("units"));
                    break;

                case "Input2D":
                    descriptor = new Input2D((int)layer.SelectToken("height"), (int)layer.SelectToken("width"),
                                             (int)layer.SelectToken("channel"), (int)layer.SelectToken("batch"));
                    break;

                case "Bias2D":
                    descriptor = new Bias2D();
                    break;

                case "Permute":
                    descriptor = new Permute(
                        (int)layer.SelectToken("dim1"),
                        (int)layer.SelectToken("dim2"),
                        (int)layer.SelectToken("dim3"));
                    break;

                case "Reshape":
                    descriptor = new Reshape2D(
                        (int)layer.SelectToken("height"),
                        (int)layer.SelectToken("width"),
                        (int)layer.SelectToken("channel"),
                        1);
                    break;

                case "RepeatVector":
                    descriptor = new RepeatVector(
                        (int)layer.SelectToken("num"));
                    break;

                case "SimpleRNN":
                    descriptor = new SimpleRNN(
                        (int)layer.SelectToken("units"),
                        (int)layer.SelectToken("input_dim"),
                        ANR((string)layer.SelectToken("activation")));
                    break;

                case "LSTM":
                    descriptor = new LSTM(
                        (int)layer.SelectToken("units"),
                        (int)layer.SelectToken("input_dim"),
                        ANR((string)layer.SelectToken("activation")),
                        ANR((string)layer.SelectToken("rec_act")));
                    break;

                case "GRU":
                    descriptor = new GRU(
                        (int)layer.SelectToken("units"),
                        (int)layer.SelectToken("input_dim"),
                        ANR((string)layer.SelectToken("activation")),
                        ANR((string)layer.SelectToken("rec_act")));
                    break;

                case "ELu":
                    descriptor = new ELu(1);
                    break;

                case "HardSigmoid":
                    descriptor = new HardSigmoid();
                    break;

                case "ReLu":
                    descriptor = new ReLu();
                    break;

                case "Sigmoid":
                    descriptor = new Sigmoid();
                    break;

                case "Flatten":
                    descriptor = new Flatten();
                    break;

                case "Softmax":
                    descriptor = new Softmax();
                    break;

                case "SoftPlus":
                    descriptor = new SoftPlus();
                    break;

                case "SoftSign":
                    descriptor = new Softsign();
                    break;

                case "TanH":
                    descriptor = new TanH();
                    break;

                default:
                    throw new Exception("Unknown layer type!");
                }

                return(descriptor);
            }).ToList();

            return(dscps);
        }