last day (14 days later) » 

1:43 PM
0
A: reshaping image array [n, width, height] to [n, height, width, channel]

AllenOk, it seems the shapes of the left and right don't match. X_gen[j][:, i*height:width + i * width, 0] has a shape of (60, 32) and the image is of shape (32,60) Maybe try the following to see if it works? X_gen[j][:, i*height:width + i * width, 0] = image.T

 
I tried but not its saying; "could not broadcast input array from shape (60,32) into shape (60,4)"
 
What's the output of X_gen.shape, height and weight?
 
(10, 60, 160, 1) which corresponds to (n, height, width, channel)
 
can you do a print(X_gen.shape),print(j), print(i), print(height), print(width) before the error line?
 
respectively (10, 60, 160, 1) 0 0 60 32
 
1:43 PM
This is weird. Those numbers look correct. Can you also do a print(X_gen[j][:, i*height:width + i * width, 0].shape) before the error line?
 
it is printing (60, 32)
 
The two error messages you've put here "could not broadcast input array from shape (32,60) into shape (60,0)" and "could not broadcast input array from shape (60,32) into shape (60,4)" seems to suggest there's something strange going on in your code. It indicates the shape of X_gen[j][:, i*height:width + i * width, 0] may change during execution time.
 
can I share the full code with you?
 
hi there
sure
 
I think I posted almost all of them :D
def gen(n=10, max_digs=1, width=32):
capgen = ImageCaptcha(width=width)
data = []
target = []
for i in range(n):
x = np.random.randint(0, 10 ** max_digs)
img = misc.imread(capgen.generate(str(x)))
img = np.mean(img, axis=2)[:, :width]
data.append(img.flatten())
target.append(x)
return np.array(data), np.array(target)


train_data, train_target = gen(10)
test_data, test_target = gen(10)

n_train, n_test = train_data.shape[0], test_data.shape[0]

train_data = train_data.reshape(train_data.shape[0], 32, 60)
 
1:46 PM
can you please send over the full error messages?
 
Traceback (most recent call last):
File "bla.py", line 90, in <module>
X_train, y_train = generate_dataset(train_data, train_target)
File "bla.py", line 83, in generate_dataset
X_gen[j][:, i * height:width + i * width, 0] = image
ValueError: could not broadcast input array from shape (32,60) into shape (60,32)
 
This is different error
can you change that line to X_gen[j][:, i * height:width + i * width, 0] = image.T and try again?
 
Traceback (most recent call last):
File "bla.py", line 70, in <module>
X_train, y_train = generate_dataset(train_data, train_target)
File "bla.py", line 62, in generate_dataset
X_gen[j][:, i * height:width + i * width, 0] = image.T
ValueError: could not broadcast input array from shape (60,32) into shape (60,4)
 
ok, can you enable these prints and try again?print(X_gen[j][:, i * height:width + i * width, 0].shape)
print(X_gen.shape)
print(j)
print(i)
print(height)
print(width)
oh, right
I think I've found where the problem is
Let me see how I can fix it
 
(60, 32)
(10, 60, 160, 1)
0
0
60
32
(60, 32)
(10, 60, 160, 1)
1
0
60
32
(60, 32)
(10, 60, 160, 1)
2
0
60
32
(60, 4)
(10, 60, 160, 1)
2
1
60
32
you will save my life :)
 
1:59 PM
ok, change that line to X_gen[j][:, i*width: (i+1)*width, 0] = image.T
 
it workedddd thank you a lot
 
That's great
 
can I ask one more question
 
sure
 
I am trying to pickle a model but it gives me permission error
temp = tempfile.NamedTemporaryFile(prefix="data.pkl", dir="C:/Users/cano/PycharmProjects/untitled",
delete=False)
print(temp.name)
pickle.dumps(model)
temp.close()
 
2:05 PM
You probably need to ask your IT support to take a look for that mate
maybe your account doesn't have required permission
 
ohh thanks you a lot again
what was the problem did you found
 
No worries. I've got to go. See you later!
[:, i * height:width + i * width, 0] calculates wrong index when i is > 0
 
got it :)
see you!
 

last day (14 days later) »