boris-kz / CogAlg

This project is a Computer Vision implementation of general hierarchical pattern discovery principles introduced in README
http://www.cognitivealgorithm.info
MIT License
91 stars 41 forks source link

intra_comp debug - comp_angle - lateral_comp - vertical_comp ... #30

Closed Twenkid closed 4 years ago

Twenkid commented 5 years ago

Sample output from Khan's test with that image, scaled down to 640x... with Ave=25

https://pixabay.com/photos/mountain-desert-landscape-nature-2143877/ comp_angle_13741_with_ave_25 comp_angle_7028_with_ave_25 comp_angle_7752_with_ave_25 comp_angle_7913_with_ave_25 comp_angle_8090_with_ave_25 comp_angle_8154_with_ave_25 comp_angle_8771_with_ave_25 comp_angle_8823_with_ave_25 comp_angle_9457_with_ave_25 comp_angle_11687_with_ave_25

comp_angle_6461_with_ave_25 comp_angle_953_with_ave_25 comp_angle_3246_with_ave_25 comp_angle_5225_with_ave_25 comp_angle_5566_with_ave_25 comp_angle_5769_with_ave_25

Twenkid commented 5 years ago

Note that both the raccoon image and the rock image from the previous test have horizontal aspect ratios X>Y. Is it possible that it has an impact on the output?

Below are the results from the image of a rocket, having a lot of smooth areas (sky), with a vertical aspect ratio and a vertical pattern, supposed vertically dominant output, tested with Ave 5,15,25.

https://www.wired.com/story/russia-blames-a-bad-sensor-for-its-failed-rocket-launch/

Note also the image-encoding artifacts. In the racoon image there are also jpg artifacts (if zoomed), hard borders between squares. I don't know if the way jpg does this could also add some kind of nasty biases.

image

comp_angle_820_with_ave_5

comp_angle_820_with_ave_15

comp_angle_820_with_ave_25

comp_angle_418_with_ave_15 comp_angle_418_with_ave_25 comp_angle_679_with_ave_5 comp_angle_679_with_ave_15

comp_angle_679_with_ave_25

comp_angle_733_with_ave_25

comp_angle_733_with_ave_15

comp_angle_733_with_ave_5

comp_angle_325_with_ave_5

comp_angle_325_with_ave_15

comp_angle_325_with_ave_25

comp_angle_418_with_ave_5

comp_angle_318_with_ave_5

comp_angle_318_with_ave_15

comp_angle_318_with_ave_25

khanh93vn commented 5 years ago

Woa! Now that's something. Boris used to say he didn't expected that much from the first (cognitive) layer.

However, the bug Boris mentioned before (horizontal bias in comparison for angle of change ) is a real one. I'm currently finding it in the code.

I'll push the update ASAP!

khanh93vn commented 5 years ago

There, I pushed the code. It should work now.

Here:

comp_angle_24911_with_ave_25 comp_angle_11944_with_ave_25

comp_angle_24911_with_ave_25 comp_angle_20116_with_ave_25 comp_angle_819_with_ave_25 comp_angle_11944_with_ave_25

khanh93vn commented 5 years ago

Oh, sorry I got them mixed up. facepalm

seems like the sky in soyuz got messed - up. Do you have an idea why it is so?

Twenkid commented 5 years ago

I will check it and play with it tomorrow. :) Good job and nice to have running code to play with. :)

Do you mean that there is no picture with a flat gray sky like in the previous version?

Something funny I find in the previous and current outputs are tiny little figures in the black sky pics, which look like sprites from an Atari 2600 game... :)

Which reminds me and confirms one observation, that the hierarchy of the complexity of the patterns in the history of video games will probably match a related hierarchy of discovered patterns within an incremental exploration.

The basic segs and blobs, same color, remind of Atari 2600 - 128 bytes RAM and a very primitive sprite-background system. All of the video game consoles before the 3D ones like the Playstation worked with a background tile sprites and foreground sprites with transparency as one of the colours. It resembles the positive-negative patterns dichotomy.

With the next generations ( Atari 5200, Atati 7800, NES, Sega Master System, Turbo Grafix, Sega Genesis, SNES), the number of colours grows, as well as the size of the sprites and the number of unique tile and foreground sprites visible in one frame and in the entire game, and the shapes and the images get more realistic.

So for me classical video games, up to Sega Genesis and SNES are candidates to be tried with the algorithm, at least in my own "games".

They provide an environment where the patterns would be quickly detected and also quickly matched to reality.

There are mainly translations. The rotations are animated, not many frames in between (like a character doing a flip). The final classical console - SNES - adds more granular scaling and rotation.

Twenkid commented 5 years ago

In general the old video games and computer graphics, as well as painting and drawing, are valuable with their selection of the most important and compressed features for their respective technical/complexity limitations.

Historically in the games there is an already recorded compressed ladder of complexity of the patterns mapping the visual world of a person, a tree, a car, a mountain etc.

Like the early 3D football games had silly humans made of 15-20 "boxes" etc., representing the most essential features for the recognition and perception of the image as a "person" etc.

khanh93vn commented 5 years ago

Ah, interesting. Atari... That reminds me of the paper about reinforment learning a few years ago, which leads to OpenAI Five... Do you aware of it? Just an off-topic

Twenkid commented 5 years ago

Hi Khan, well, I think I didn't know about OpenAI Five but I was aware of the ALE (Arcade Learning Environment): https://github.com/mgbellemare/Arcade-Learning-Environment and also I remember the breakthrough work in RL of DeepMind for Atari 2600.

EDIT: I may have heard of it somewhere in the news feeds, but not studied.

As of the cv2 problems and Py 2.7 that you mentioned - on my setup with Py 3.6.1, Pycharm complains about imports of CogAlg modules (red underlining):

from comp_range import comp_range from comp_angle import comp_angle

This seems cosmetic though, it runs normally.

Twenkid commented 5 years ago

Like this:

image

Twenkid commented 5 years ago

@boris-kz BTW, do you know about these depth cameras, for the 3D version depth could be provided as input directly: https://www.youtube.com/watch?v=Pp18JL6H2zc

So stereo-vision induced 3D could be compared to the ground-truth from such sensors.

(They are not new as a technology, the early popular ones started from Kinect, but you still don't mention them in the introduction:

"Initial testing could be on recognition of labeled images, but video or stereo video should be much better. We will then add colors, maybe audio and text." )

Twenkid commented 5 years ago

Hi,

I see you've defined a default lambda function*:

calc_g = (lambda dx, dy, ncomp: int(hypot(dx, dy)))

However ncomp and the division are not used in compute_g, as suggested when applying calc_g in the function:

def compute_g_(derts__, calc_g):

    for x0, derts_ in derts__:
        for derts in derts_:
            dy, dx, ncomp = derts[-1]

            g = calc_g(dx, dy, ncomp)   # calculate g as hypot(dx,dy) / ncomp
            derts[-1] = (g,) + derts[-1]

I didn't see intra_blob calling the function with an override value.

What would be other variants?

Also I notice that you collect in neweval the val(...) tuples which which pass progressively > Aves

cyc is supposed to be used for accessing respective prior derts (it is negative [-1], [-2]...) in feedback_draft.

Indeed:

if blob.cyc > len(root_blob.Derts): # cycle( alt( type Dert

cyc is supposed to be negative, so this is always true even for empty Derts, thus:

if -blob.cyc > or if abs(blob.cyc)?

...

Why val_rg and _rga are computed the same way?

                    val_rg  = G + Ga  # value of rng=2 gradient deviation, non-directional
                    val_rga = G + Ga  # value of rng=2 angle gradient deviation, with comp_angle

                    eval_fork_ += [   # sort while appending?  adjust vals by lower Gs?
                        (val_gga, Ave_blob,     comp_gradient, 0, -1, 2, 1),  # current cyc and typ, rng = 1
                        (val_rga, Ave_blob * 2, comp_range, 0,     -1, 1, 2),  # current cyc, higher typ, rng = 2
                        (val_gg,  Ave_blob * 2, comp_gradient, 0, -1, 0, 1),  # current cyc, higher typ, rng = 1
                        (val_rg,  Ave_blob * 2, comp_range,       0, -2, 0, 2)   # higher cyc and typ, rng = 2
                        ]
khanh93vn commented 5 years ago

Ah, currently, intra_comp and branches are being reworked.