Skip to content

Chap15 conv1d and conv2d #132

Description

@JohannWO

When running the naive Implementation of conv1d and conv2d with example in book then it shows wrong results.

conv1d works for
X = [[1, 3, 2, 4], [5, 6, 1, 3], [1, 2, 0, 2], [3, 4, 3, 2]]
W = [[1, 0, 3], [1, 2, 1], [0, 1, 1]]
Conv1d Implementation p=2 s=1: [ 5. 14. 16. 26. 24. 34. 19. 22.] <- Correct

conv1d for (German Book, 2. Auflage, Seite 493)
x= [3, 2, 1, 7, 1, 2, 5, 4]
w= [0.5, 0.75, 1.0, 0.25]
Conv1d Implementation p=0 s=2: [7. 9.] <- Wrong
Expected: [7 9 8]

conv2d works for
X= [[1, 3, 2, 4], [5, 6, 1, 3], [1, 2, 0, 2], [3, 4, 3, 2]]
W= [[1, 0, 3], [1, 2, 1], [0, 1, 1]]
Correct Result

conv2d for (German Book, 2. Auflage, Seite 498)
X= [[2, 1, 2], [5, 0, 1], [1, 7, 3]]
W= [[0.5, 0.7, 0.4], [0.3, 0.4, 0.1], [0.5, 1.0, 0.5]]
Conv2d Implementation p=1,1 s=2,2: [[4.6]]
Expected: [[4.6, 1.6], [7.5, 2.9]

Even if both implementations are called naive, they should return correct results.
I think the problem is the end-condition in the for-statement.

conv1d
book: for j in range(0, int(len(x)/s), s):
new: for j in range(0, len(x_padded)-len(w_rot)+1, s):

conv2d
book:
for i in range(0, int((X_padded.shape[0] - W_rot.shape[0]) / s[0]) + 1, s[0]): # Fehler bei s=2,2
for j in range(0, int((X_padded.shape[1] - W_rot.shape[1]) / s[1]) + 1, s[1]): # Fehler bei s=2,2
new:
for i in range(0, int((X_padded.shape[0] - W_rot.shape[0]) ) + 1, s[0]):
for j in range(0, int((X_padded.shape[1] - W_rot.shape[1]) ) + 1, s[1]):

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions