classdef plresizelayer < nnet.layer.Layer % & nnet.layer.Formattable (Optional)
  properties
    mindimension
  end

  methods
    function layer = plresizelayer(mindim, name)
      layer.Name = name;
      layer.Description = 'Custom resize layer';
      layer.mindimension = mindim;
    end

    function Z = predict(layer,X)
      s = size(X);
      m = min(s(1),s(2));
      yn = round(s(1)/m*layer.mindimension);
      xn = round(s(2)/m*layer.mindimension);
      Z = dlresize(X,'OutputSize',[yn xn], 'DataFormat', 'SSCB');
    end

    function Z = forward(layer,X)
      s = size(X);
      m = min(s(1),s(2));
      yn = round(s(1)/m*layer.mindimension);
      xn = round(s(2)/m*layer.mindimension);
      Z = dlresize(X,'OutputSize',[yn xn], 'DataFormat', 'SSCB');
    end
  end
end
