Skip to content

Commit

Permalink
fix a large amount of error
Browse files Browse the repository at this point in the history
  • Loading branch information
szou28 committed Nov 20, 2017
1 parent 8d6e056 commit 7ef00bd
Show file tree
Hide file tree
Showing 27 changed files with 346 additions and 832 deletions.
10 changes: 5 additions & 5 deletions AugmentUtils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from enum import Enum
import abc
import random
import Utils
from datetime import datetime

class RANDTYPE(Enum):
Expand Down Expand Up @@ -40,8 +41,7 @@ def Augment(self, datum):
y = 0
while y < self.__coords.ColumnCount:
idx = self.__coords.GetIndex(c, x, y)
#__ newdatum[idx] = Utils.UMath.Clamp(datum[idx] + eps, Utils.RobustnessOptions.MinValue, Utils.RobustnessOptions.MaxValue)
# FIX ME
newdatum[idx] = Utils.UMath.Clamp(datum[idx] + eps, Utils.RobustnessOptions.MinValue, Utils.RobustnessOptions.MaxValue)
y += 1
x += 1
c += 1
Expand Down Expand Up @@ -96,7 +96,7 @@ def Augment(self, datum):
y += 1
x += 1
c += 1
newdatums.Add(newdatum)
newdatums.append(newdatum)
i += 1
return newdatums

Expand All @@ -122,7 +122,7 @@ def Augment(self, datum):
real_agle = eps * self.__degrees
#__ newdatum_int = Utils.UDraw.Rotate(datum_int, self.__coords.RowCount, self.__coords.ColumnCount, (self.__coords.ChannelCount > 1), real_agle)
#__ Utils.UDraw.DisplayImageAndPause(newdatum_int, 32, 32, True)
#__ newdatums.Add(Utils.UArray.ToDoubleArray(newdatum_int))
#__ newdatums.append(Utils.UArray.ToDoubleArray(newdatum_int))
i += 1
return newdatums

Expand All @@ -144,7 +144,7 @@ def Augment(self, datum):
datum_int = Utils.UArray.ToIntArray(datum)
photoquality = self.__random.Next(self.__loss, 101)
#__ newdatum_int = Utils.UDraw.LossyJPGAndBack(datum_int, self.__coords.RowCount, self.__coords.ColumnCount, (self.__coords.ChannelCount > 1), photoquality)
#__ newdatums.Add(Utils.UArray.ToDoubleArray(newdatum_int))
#__ newdatums.append(Utils.UArray.ToDoubleArray(newdatum_int))
i += 1
return newdatums

Expand Down
11 changes: 7 additions & 4 deletions AvgPoolingLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ def __init__(self, index, input_Coordinates, kernelDimension, padding, stride):
super().__init__(index, input_Coordinates, kernelDimension, padding, stride)

def Instrument(self, instr, input_, output):
#__ instr[Index] = Instrumentation.NoInstrumentation()
raise NotImplementedError("Instrumentation")
instr[Index] = Instrumentation.NoInstrumentation()

def ApplyKernelConcrete(self, instr, input_, outIndex, channel, row, column):
return self.ApplyKernel(input_, channel, row, column)
Expand All @@ -20,16 +21,18 @@ def ApplyKernel(self, input_, channel, row, column):
while j < KernelDimension:
x = row - Padding + i
y = column - Padding + j
if x >= InputCoordinates.RowCount or y >= InputCoordinates.ColumnCount:
if x >= InputCoordinates.R or y >= InputCoordinates.ColumnCount:
continue
index = InputCoordinates.GetIndex(channel, x, y)
if index < 0 or index >= input_.Count:
continue
.Add(, input_[index])
sum_ += input_[index]
raise NotImplementedError("Plz confirm")
count += 1
j += 1
i += 1
.Mul(, 1.0 / count)
sum_ *= (1.0 / count)
raise NotImplementedError("What is .?")
return sum_

def IsAffine(self):
Expand Down
13 changes: 10 additions & 3 deletions ConvolutionLayer.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import DenseMatrix
import DenseVector
import Utils
class ConvolutionLayer(Layer):
# let V = channels * kernelrows * kernelcolumns # kernelCount * V
# Scratchpad stuff # #kernels x kernelpositions copies of the intercept vector. # kernelmatrix.ColumnCount x kernelpositions # kernelmatrix.RowCount * kernelpositions
def InputToScratch(self, input):
# Must populate _input_scratch :: kernelMatrix.ColumnCount x kernel-positions
raise NotImplementedError("Where is the def of InputCoordinates?")
jBound = Utils.UImageCoordinate.ComputeOutputCounts(KernelDimension, InputCoordinates.RowCount, 1, Padding, False)
kBound = Utils.UImageCoordinate.ComputeOutputCounts(KernelDimension, InputCoordinates.ColumnCount, 1, Padding, False)
row = 0
Expand Down Expand Up @@ -41,10 +43,11 @@ def OutputScratchToRes(self, output_scratch):
def DoConvolution(self, input_):
self.InputToScratch(input_)
self._kernelMatrix_.Multiply(self.__input_scratch.Value, self.__output_scratch.Value)
self.__output_scratch.Value.Add(self.__intercept_scratch, self.__output_scratch.Value)
self.__output_scratch.Value.append(self.__intercept_scratch, self.__output_scratch.Value)
return self.OutputScratchToRes(self.__output_scratch.Value)

def CheckInitThreadLocalScratch(self, kernelpositions):
raise NotImplementedError("What should we do to deal with ThreadLocal variables?")
self.__input_scratch = ThreadLocal[Matrix]()
self.__output_scratch = ThreadLocal[Matrix]()
self.__output_result = ThreadLocal[Vector]()
Expand Down Expand Up @@ -123,6 +126,7 @@ def get_KernelCoordinates(self):
KernelCoordinates = property(fget=get_KernelCoordinates)

def Instrument(self, instr, input_, output):
raise NotImplementedError("Instrumentation")
instr[Index] = Instrumentation.NoInstrumentation()

def ApplyKernel(self, output, input_, padding, kernel, row, column):
Expand All @@ -142,15 +146,17 @@ def ApplyKernel(self, output, input_, padding, kernel, row, column):
k += 1
j += 1
i += 1
.Add(, self.Intercepts[kernel])
.append(, self.Intercepts[kernel])
return

def Evaluate(self, input_):
raise NotImplementedError("Don't know how to deal with this situation. What is NumT?")
output = .CreateVector(OutputDimension) # Has initialized all values to 0.0
self.Evaluate(input_, output)
return output

def Evaluate(self, input_, output):
raise NotImplementedError("Don't know how to deal with Parallelism.")
jBound = Utils.UImageCoordinate.ComputeOutputCounts(self.KernelDimension, InputCoordinates.RowCount, 1, self.Padding, False)
kBound = Utils.UImageCoordinate.ComputeOutputCounts(self.KernelDimension, InputCoordinates.ColumnCount, 1, self.Padding, False)
Parallel.For(0, self.KernelCount, ParallelOptions(MaxDegreeOfParallelism = Environment.ProcessorCount), )
Expand All @@ -161,7 +167,8 @@ def EvaluateConcrete(self, input_):

def EvaluateSymbolic(self, state, input_):
if not self._symbolic_output_storage.IsValueCreated:
self._symbolic_output_storage.Value = .CreateVector(OutputDimension)
raise NotImplementedError("What is NumInstLPSTermArr?")
self._symbolic_output_storage.Value = NumInstLPSTermArr.CreateVector(OutputDimension)
self.Evaluate(input_, self._symbolic_output_storage.Value)
return self._symbolic_output_storage.Value

Expand Down
55 changes: 29 additions & 26 deletions DataLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def __init__(self):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def TransformedCoordinates(self):
raise NotImplementedError("Please use a concrete ITransform object")
pass

@abc.abstractmethod
def OriginalCoordinates(self):
Expand All @@ -22,15 +22,15 @@ def OriginalDimension(self):
raise NotImplementedError("Please use a concrete ITransform object")

@abc.abstractmethod
def Transform(self, input):
def Transform(self, input_):
raise NotImplementedError("Please use a concrete ITransform object")

@abc.abstractmethod
def UnTransform(self, original, image):
raise NotImplementedError("Please use a concrete ITransform object")

@abc.abstractmethod
def Transform(self, input):
def Transform(self, input_):
raise NotImplementedError("Please use a concrete ITransform object")

class CropTransform(ITransform):
Expand Down Expand Up @@ -77,7 +77,8 @@ def UnTransform(self, orig, image):
channel += 1
return ret

def TransformGeneric(self, input):
def TransformGeneric(self, input_):
raise NotImplementedError("What's the meaning of default(xxx) in C sharp?")
if not self._fromCenter_:
raise NotImplementedException("Non-center image cropping not supported yet!")
center_row = self._inputCoordinates_.RowCount / 2
Expand All @@ -94,22 +95,22 @@ def TransformGeneric(self, input):
input_idx = self._inputCoordinates_.GetIndex(channel, topleft_row + i, topleft_col + j)
output_idx = self._outputCoordinates_.GetIndex(channel, i, j)
if input_idx >= 0 and input_idx < self._inputDimension_ and output_idx >= 0 and output_idx < self._outputDimension_:
z = .Const(0.0)
.Add(, input[input_idx])
z = 0.0
z += input_[input_idx]
output[output_idx] = z
j += 1
i += 1
channel += 1
return output

def Transform(self, input):
# Utils.UDraw.DisplayImageAndPause(Utils.UArray.ToRGBArray(input.ToArray(), 128, 127), 32, 32, true);
output = self.TransformGeneric(input)
def Transform(self, input_):
# Utils.UDraw.DisplayImageAndPause(Utils.UArray.ToRGBArray(input_.ToArray(), 128, 127), 32, 32, true);
output = self.TransformGeneric(input_)
# Utils.UDraw.DisplayImageAndPause(Utils.UArray.ToRGBArray(output.ToArray(), 128, 127), 30, 30, true);
return output

def Transform(self, input):
return self.TransformGeneric(input)
def Transform(self, input_):
return self.TransformGeneric(input_)

class DataLayer(Layer):
# Scaling
Expand All @@ -125,7 +126,7 @@ def __init__(self, index, inputDimension, inputCoordinates, scale, meanImage, me
self._meanImage_ = meanImage
if meanChannel != None and meanChannel.Count > 0:
channel_count = inputCoordinates.ChannelCount
self._meanChannel_ = Array.CreateInstance(Double, channel_count)
self._meanChannel_ = [None] * channel_count
i = 0
while i < channel_count:
self._meanChannel_[i] = meanChannel[i % meanChannel.Count()]
Expand All @@ -140,49 +141,51 @@ def __init__(self, index, inputDimension, inputCoordinates, scale, meanImage, me
self._meanImage_ = meanImage
if meanChannel != None and meanChannel.Count > 0:
channel_count = inputCoordinates.ChannelCount
self._meanChannel_ = Array.CreateInstance(Double, channel_count)
self._meanChannel_ = [None] * channel_count # [None] * channel_count
i = 0
while i < channel_count:
self._meanChannel_[i] = meanChannel[i % meanChannel.Count()]
i += 1
self.InitLayer(index, LayerType.DATA_LAYER, inputDimension, inputDimension, inputCoordinates, inputCoordinates)

def Instrument(self, instr, input, output):
def Instrument(self, instr, input_, output):
raise NotImplementedError("Instrumentation?")
instr[Index] = Instrumentation.NoInstrumentation()

def IsAffine(self):
return False
# Oh well just just don't coalesce across data layer although technically it's entirely possible
def EvaluateConcrete(self, input):
def EvaluateConcrete(self, input_):
# If we have a meanImage ...
if self._meanImage_ != None:
return (input - DenseVector.OfArray(self._meanImage_)) * self._scale_
return (input_ - DenseVector.OfArray(self._meanImage_)) * self._scale_
# If we have a meanChannel ...
if self._meanChannel_ != None and self._meanChannel_.Count() > 0:
cur = input
cur = input_
channel = 0
while channel < InputCoordinates.ChannelCount:
r = 0
while r < InputCoordinates.RowCount:
c = 0
while c < InputCoordinates.ColumnCount:
index = InputCoordinates.GetIndex(channel, r, c)
cur[index] = (input[index] - self._meanChannel_[channel]) * self._scale_
cur[index] = (input_[index] - self._meanChannel_[channel]) * self._scale_
c += 1
r += 1
channel += 1
return cur
# If we are only doing scaling ...
return (input * self._scale_)
return (input_ * self._scale_)

def EvaluateSymbolic(self, state, input):
cur = .CreateVector(input.Length)
def EvaluateSymbolic(self, state, input_):
raise NotImplementedError("Don't know what is NumInst... line 285")
cur = .CreateVector(input_.Length)
# If we have a meanImage ...
if self._meanImage_ != None:
i = 0
while i < input.Length:
while i < input_.Length:
cur[i].Sub(LPSTerm.Const(self._meanImage_[i])) # - mean
cur[i].Add(input[i]) # + input
cur[i].append(input_[i]) # + input_
cur[i].Mul(self._scale_)
i += 1
return cur
Expand All @@ -196,16 +199,16 @@ def EvaluateSymbolic(self, state, input):
while c < InputCoordinates.ColumnCount:
index = InputCoordinates.GetIndex(channel, r, c)
cur[index].Sub(LPSTerm.Const(self._meanChannel_[channel]))
cur[index].Add(input[index])
cur[index].append(input_[index])
cur[index].Mul(self._scale_)
c += 1
r += 1
channel += 1
return cur
# Finally, if we are only doing scaling ...
i = 0
while i < input.Length:
cur[i].Add(input[i])
while i < input_.Length:
cur[i].append(input_[i])
cur[i].Mul(self._scale_)
i += 1
return cur
Loading

0 comments on commit 7ef00bd

Please sign in to comment.