In [2]:
import neukrill_net.highlevelfeatures as hlf

In [4]:
import neukrill_net.utils

In [18]:
import numpy as np

In [10]:
import imp

In [6]:
cd ..


/home/scott/Documents/git/neukrill-net-work

In [7]:
# Load the settings 
settings = neukrill_net.utils.Settings("settings.json")
# Load raw training data
rawdata, labels = neukrill_net.utils.load_rawdata(settings.image_fnames, classes=settings.classes)

In [48]:
imp.reload(hlf)
foo = hlf.HighLevelFeatureBase(preprocessing_func=lambda x:np.array([1]))

In [104]:
imp.reload(hlf)
attrlist = ['mean','std']
boa = hlf.BasicAttributes(attrlist, preprocessing_func=None, augment_func=None)

In [46]:
X1 = boa.transform(rawdata)

In [55]:
pths = [pth for k in settings.image_fnames['train'].keys() for pth in settings.image_fnames['train'][k]]
X2 = boa.transform(pths)

In [50]:
X3 = boa.transform(settings.image_fnames['test'])

In [56]:
print X1.shape
print X2.shape
print X3.shape


(1, 30336, 2)
(1, 30336, 2)
(1, 130400, 2)

In [57]:
X1


Out[57]:
array([[[ 252.09887006,   18.75980781],
        [ 251.92009494,   15.17674691],
        [ 252.98199609,   13.28779985],
        ..., 
        [ 239.72400932,   45.8527623 ],
        [ 245.21540179,   32.74163994],
        [ 247.25510923,   31.15009075]]])

In [58]:
X2


Out[58]:
array([[[ 229.07122093,   57.79984397],
        [ 231.68031746,   54.6052125 ],
        [ 207.62609477,   78.85547567],
        ..., 
        [ 247.        ,   27.79786523],
        [ 245.49945652,   28.53548515],
        [ 236.45587302,   44.96691329]]])

In [59]:
X3


Out[59]:
array([[[ 249.4874552 ,   17.94672583],
        [ 248.13024476,   28.05088087],
        [ 239.21591784,   38.27541707],
        ..., 
        [ 231.95572917,   57.2911238 ],
        [ 245.4853364 ,   27.88387132],
        [ 249.08700322,   24.41380314]]])

In [116]:
imp.reload(hlf)
boa2 = hlf.BasicAttributes(['mean','height'])
mHLF1 = hlf.MultiHighLevelFeature([boa,boa2])
mHLF2 = boa + boa2

In [106]:
print boa.transform(rawdata[:10])
print boa2.transform(rawdata[:10])
print mHLF1.transform(rawdata[:10])
print mHLF2.transform(rawdata[:10])


[[[ 252.09887006   18.75980781]
  [ 251.92009494   15.17674691]
  [ 252.98199609   13.28779985]
  [ 253.21413341    9.97854024]
  [ 252.51965786   15.4812235 ]
  [ 253.16030093   11.06280986]
  [ 251.54252137   17.85879765]
  [ 251.76464047   18.43928537]
  [ 251.89041096   19.29495914]
  [ 252.8630925    14.96741775]]]
[[[ 252.09887006   66.        ]
  [ 251.92009494   80.        ]
  [ 252.98199609   70.        ]
  [ 253.21413341   67.        ]
  [ 252.51965786   98.        ]
  [ 253.16030093   48.        ]
  [ 251.54252137   78.        ]
  [ 251.76464047   71.        ]
  [ 251.89041096   73.        ]
  [ 252.8630925    82.        ]]]
[[[ 252.09887006   18.75980781  252.09887006   66.        ]
  [ 251.92009494   15.17674691  251.92009494   80.        ]
  [ 252.98199609   13.28779985  252.98199609   70.        ]
  [ 253.21413341    9.97854024  253.21413341   67.        ]
  [ 252.51965786   15.4812235   252.51965786   98.        ]
  [ 253.16030093   11.06280986  253.16030093   48.        ]
  [ 251.54252137   17.85879765  251.54252137   78.        ]
  [ 251.76464047   18.43928537  251.76464047   71.        ]
  [ 251.89041096   19.29495914  251.89041096   73.        ]
  [ 252.8630925    14.96741775  252.8630925    82.        ]]]
[[[ 252.09887006   18.75980781  252.09887006   66.        ]
  [ 251.92009494   15.17674691  251.92009494   80.        ]
  [ 252.98199609   13.28779985  252.98199609   70.        ]
  [ 253.21413341    9.97854024  253.21413341   67.        ]
  [ 252.51965786   15.4812235   252.51965786   98.        ]
  [ 253.16030093   11.06280986  253.16030093   48.        ]
  [ 251.54252137   17.85879765  251.54252137   78.        ]
  [ 251.76464047   18.43928537  251.76464047   71.        ]
  [ 251.89041096   19.29495914  251.89041096   73.        ]
  [ 252.8630925    14.96741775  252.8630925    82.        ]]]

In [107]:
mHLF2._childHLFs


Out[107]:
[<neukrill_net.highlevelfeatures.BasicAttributes instance at 0x7fc5517a8c68>,
 <neukrill_net.highlevelfeatures.BasicAttributes instance at 0x7fc5517756c8>]

In [108]:
np.ravel(mHLF2._childHLFs[0]._preprocess_extract_image(rawdata[0]))


Out[108]:
array([ 252.09887006,   18.75980781])

In [109]:
[child._preprocess_extract_image(rawdata[0]).ravel() for child in mHLF2._childHLFs]


Out[109]:
[array([ 252.09887006,   18.75980781]), array([ 252.09887006,   66.        ])]

In [121]:
bow = hlf.BagOfWords(preprocessing_func= n_features_max=500, patch_size=17, clusteralgo='kmeans', n_clusters=10, random_seed=42)

In [123]:
bow.transform(X1)


---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-123-2914307a1927> in <module>()
----> 1 bow.transform(X1)

/home/scott/Documents/git/neukrill-net-tools/neukrill_net/highlevelfeatures.py in transform(self, images)
    153         num_augmentations = len(self.augment_image(first_image))
    154         # How many elements are in the feature vector from each image?
--> 155         num_feature_elements = self._preprocess_extract_image(first_image).size
    156 
    157         # Initialise

/home/scott/Documents/git/neukrill-net-tools/neukrill_net/highlevelfeatures.py in _preprocess_extract_image(self, image)
    130         NOTE: Subclasses should not modify this function!
    131         """
--> 132         return self.preprocess_image(self.extractfeatures_image(image))
    133 
    134 

/home/scott/Documents/git/neukrill-net-tools/neukrill_net/highlevelfeatures.py in extractfeatures_image(self, image)
    380         """
    381         # Get the descriptions of every keypoint in the image
--> 382         X = self.describeImage(image)
    383         if X is None:
    384             # No keypoints, so occurances of any words

/home/scott/Documents/git/neukrill-net-tools/neukrill_net/highlevelfeatures.py in describeImage(self, image)
    332                       which varies between images.
    333         """
--> 334         _, des = self.detector.detectAndCompute(image, None)
    335         return des
    336 

error: /home/scott/Documents/git/opencv-3.0.0-beta/modules/imgproc/src/color.cpp:5511: error: (-215) depth == CV_8U || depth == CV_16U || depth == CV_32F in function cvtColor