2using System.Collections.Generic;
14 [TypeConverter(typeof(ExpandableObjectConverter))]
51 [Description(
"Specifies the output dimensions.")]
54 get {
return m_shape; }
55 set { m_shape = value; }
79 [Description(
"Specifies the axis portion of the bottom blob's shape that is replaced by (included in) the reshape. By default (axis == 0 and num_axes == 1), the entire bottom blob is included in the reshape, and hence the shape field must specifiethe entire output shape.")]
82 get {
return m_nAxis; }
83 set { m_nAxis = value; }
108 [Description(
"Specifies the number of axes which specifies the extent of the reshape.")]
111 get {
return m_nNumAxes; }
112 set { m_nNumAxes = value; }
116 public override object Load(
System.IO.BinaryReader br,
bool bNewInstance =
true)
132 if (p.m_shape !=
null)
133 m_shape = p.m_shape.
Clone();
136 m_nNumAxes = p.m_nNumAxes;
159 rgChildren.
Add(
"axis",
axis.ToString());
164 return new RawProto(strName,
"", rgChildren);
181 if ((strVal = rp.
FindValue(
"axis")) !=
null)
182 p.
axis =
int.Parse(strVal);
184 if ((strVal = rp.
FindValue(
"num_axes")) !=
null)
190 private static int count(List<int> rg,
int nStart,
int nEnd)
194 for (
int i = nStart; i < nEnd; i++)
212 List<int> rgCopyAxes =
new List<int>();
218 int top_num_axes = top_blob_shape.
dim.Count();
220 for (
int i = 0; i < top_num_axes; i++)
222 int top_dim = top_blob_shape.
dim[i];
228 else if (top_dim == -1)
231 log.CHECK_EQ(nInferredAxis, -1,
"new shape contains multiple -1 dims; at most a single (1) value of -1 may be specified.");
237 nConstantCount *= top_dim;
254 public static List<int>
Reshape(
LayerParameter p, List<int> rgShape, List<int> rgCopyAxes,
int nInferredAxis,
int nConstantCount,
Log log =
null)
256 int num_axes1 = rgShape.Count;
258 int start_axis = (input_start_axis >= 0) ? input_start_axis : num_axes1 + input_start_axis + 1;
262 log.CHECK_GE(start_axis, 0,
"axis " + input_start_axis.ToString() +
" out of range");
263 log.CHECK_LE(start_axis, num_axes1,
"axis " + input_start_axis.ToString() +
" out of range for " + num_axes1.ToString() +
"-D input blob");
268 log.CHECK_GE(
num_axes, -1,
"num_axes must be >= 0, or -1 for all");
272 log.CHECK_LE(end_axis, num_axes1,
"end_axis = axis + num_axes is out of range");
274 int num_axes_replaced = end_axis - start_axis;
275 int num_axes_retained = num_axes1 - num_axes_replaced;
277 int num_new_axes = top_blob_shape.
dim.Count;
278 List<int> rgTopShape =
new List<int>();
279 int top_shape_index = 0;
281 for (
int i = 0; i < start_axis; i++)
283 rgTopShape.Add(rgShape[i]);
287 for (
int i = 0; i < num_new_axes; i++)
289 rgTopShape.Add(top_blob_shape.
dim[i]);
293 for (
int i = end_axis; i < num_axes1; i++)
295 rgTopShape.Add(rgShape[i]);
300 log.CHECK_EQ(top_shape_index, rgTopShape.Count,
"The top shape count should equal the top_shape_index.");
302 for (
int i = 0; i < rgCopyAxes.Count; i++)
304 int copy_axis_index = rgCopyAxes[i];
307 log.CHECK_GT(num_axes1, start_axis + copy_axis_index,
"new shape contains a 0, but there was no corresponding bottom axis to copy");
309 rgTopShape[start_axis + copy_axis_index] = rgShape[start_axis + copy_axis_index];
312 if (nInferredAxis >= 0)
316 int explicit_count = nConstantCount;
317 explicit_count *= count(rgShape, 0, start_axis);
318 explicit_count *= count(rgShape, end_axis, rgShape.Count);
320 for (
int i = 0; i < rgCopyAxes.Count; i++)
322 int copy_axis_index = rgCopyAxes[i];
323 explicit_count *= rgTopShape[start_axis + copy_axis_index];
326 int nCount = count(rgShape, 0, rgShape.Count);
329 log.CHECK_EQ(0, nCount % explicit_count,
"bottom count (" + nCount.ToString() +
") must be divisible by the product of the specified dimensions( " + explicit_count.ToString() +
")");
331 int inferred_dim = nCount / explicit_count;
332 rgTopShape[start_axis + nInferredAxis] = inferred_dim;
The Log class provides general output in text form.
The RawProtoCollection class is a list of RawProto objects.
void Add(RawProto p)
Adds a RawProto to the collection.
The RawProto class is used to parse and output Google prototxt file data.
RawProto FindChild(string strName)
Searches for a given node.
static RawProto Parse(string str)
Parses a prototxt and places it in a new RawProto.
string FindValue(string strName)
Searches for a falue of a node within this nodes children.
Specifies the shape of a Blob.
override RawProto ToProto(string strName)
Converts the BlobShape to a RawProto.
BlobShape Clone()
Creates a copy of the BlobShape.
static BlobShape FromProto(RawProto rp)
Parse a new BlobShape from a RawProto.
List< int > dim
The blob shape dimensions.
The LayerParameterBase is the base class for all other layer specific parameters.
Specifies the base parameter for all layers.
ReshapeParameter reshape_param
Returns the parameter set when initialized with LayerType.RESHAPE
Specifies the parameters for the ReshapeLayer.
static List< int > CalculateCopyAxes(LayerParameter p, out int nInferredAxis, out int nConstantCount, Log log=null)
Calculate the Copy Axes, inferred axis and constant count.
static List< int > Reshape(LayerParameter p, List< int > rgShape, List< int > rgCopyAxes, int nInferredAxis, int nConstantCount, Log log=null)
Calculates the new shape.
int num_axes
num_axes specifies the extent of the reshape.
int axis
Specifies the axis portion of the bottom blob's shape that is replaced by (included in) the reshape....
BlobShape shape
Specifies the output dimensions.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
override void Copy(LayerParameterBase src)
Copy on parameter to another.
static ReshapeParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
ReshapeParameter()
Constructor for the parameter.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
The MyCaffe.param namespace contains parameters used to create models.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...