'NoneType' object is not subscriptable
And can't figure out why.
Ive done some searching around, but each of the issues seems to be different to mine
https://github.com/DEAP/deap/issues/142: Not using this method of compile
https://groups.google.com/forum/#!topic/deap-users/NgL8_rYr4MI: I have an input to my tree defined
I created a minimal example that is causing this issue here: https://gist.github.com/ben-ix/284b301eba0e819c0a0722c8bcc1acbc
For completeness, heres a sample tree generated
So the structure is being enforced. The image (ARG0) is being used as input, a shape has also been selected as a terminal.
These are then passed into the example function, with the correct branch ordering being used so the strongly typed structure is there.
The textual representation of the tree is also correct, giving: eg(ARG0, Shape(Ellipse)), and I have defined both a __repr__ and
a __str__ method for the two classes (as I was getting another error without this).
The output of this function/tree should just be 1, due to this being hardcoded for the example. However, the problem occurs when trying
to run an executable version of the tree, i.e.
output = toolbox.compile(expr=individual)
label = output(sample_img)
Running this will throw the following error on the output call
<string> in <lambda>(ARG0) TypeError: 'NoneType' object is not subscriptable
What can I do to solve this, any help would be greatly appreciated.
Thank you
pset = deap.gp.PrimitiveSetTyped("MAIN", [], SuperCustomClass, "IN")
...
pset.addPrimitive(typed_super_custom_class,
[CustomClass1, CustomClass2],
SuperCustomClass)
...
def typed_super_custom_class(cc1, cc2):
return SuperCustomClass(cc1, cc2)
class Wrapper:
def __init__(self, value):
self.value = value
def __str__(self):
return "Wrapper(" + repr(self.value) + ")"
__repr__ = __str__
pset.addEphemeralConstant("Custom", lambda: Custom() , Custom)
pset.context["Custom"] = Custom