|
25 | 25 | I didnt spend much time on this behavior, but if someone has answer to this then please do comment and let me know. |
26 | 26 | ValueError: Negative dimension size caused by subtracting 3 from 1 for 'conv2d_1/convolution' (op: 'Conv2D') with input shapes: [?,1,200,200], [3,3,200,32]. |
27 | 27 | ''' |
28 | | -K.set_image_dim_ordering('th') |
| 28 | +#K.set_image_dim_ordering('th') |
| 29 | +K.set_image_data_format('channels_first') |
29 | 30 |
|
30 | 31 |
|
31 | 32 | import numpy as np |
@@ -217,8 +218,7 @@ def guessGesture(model, img): |
217 | 218 | #prob_array = model.predict_proba(rimage) |
218 | 219 |
|
219 | 220 | prob_array = get_output([rimage, 0])[0] |
220 | | - |
221 | | - #print prob_array |
| 221 | + #print('prob_array: ',prob_array) |
222 | 222 |
|
223 | 223 | d = {} |
224 | 224 | i = 0 |
@@ -327,27 +327,34 @@ def trainModel(model): |
327 | 327 | hist = model.fit(X_train, Y_train, batch_size=batch_size, epochs=nb_epoch, |
328 | 328 | verbose=1, validation_split=0.2) |
329 | 329 |
|
330 | | - visualizeHis(hist) |
331 | | - |
332 | 330 | ans = input("Do you want to save the trained weights - y/n ?") |
333 | 331 | if ans == 'y': |
334 | 332 | filename = input("Enter file name - ") |
335 | 333 | fname = path + str(filename) + ".hdf5" |
336 | 334 | model.save_weights(fname,overwrite=True) |
337 | 335 | else: |
338 | 336 | model.save_weights("newWeight.hdf5",overwrite=True) |
| 337 | + |
| 338 | + visualizeHis(hist) |
339 | 339 |
|
340 | 340 | # Save model as well |
341 | 341 | # model.save("newModel.hdf5") |
342 | 342 | #%% |
343 | 343 |
|
344 | 344 | def visualizeHis(hist): |
345 | 345 | # visualizing losses and accuracy |
346 | | - |
| 346 | + keylist = hist.history.keys() |
| 347 | + #print(hist.history.keys()) |
347 | 348 | train_loss=hist.history['loss'] |
348 | 349 | val_loss=hist.history['val_loss'] |
349 | | - train_acc=hist.history['acc'] |
350 | | - val_acc=hist.history['val_acc'] |
| 350 | + |
| 351 | + #Tensorflow new updates seem to have different key name |
| 352 | + if 'acc' in keylist: |
| 353 | + train_acc=hist.history['acc'] |
| 354 | + val_acc=hist.history['val_acc'] |
| 355 | + else: |
| 356 | + train_acc=hist.history['accuracy'] |
| 357 | + val_acc=hist.history['val_accuracy'] |
351 | 358 | xc=range(nb_epoch) |
352 | 359 |
|
353 | 360 | plt.figure(1,figsize=(7,5)) |
|
0 commit comments