Lesson 1 discussion

I will review. Thank a lot

I met lots of problem while learning lesson1, beg for help!
I’m using OS X
when I run the following code

vgg = Vgg16()
# Grab a few images at a time for training and validation.
# NB: They must be in subdirectories named based on their category
batches = vgg.get_batches(path+'train', batch_size=batch_size)
val_batches = vgg.get_batches(path+'valid', batch_size=batch_size*2)
vgg.finetune(batches)
vgg.fit(batches, val_batches, nb_epoch=1)

I met the following problem:

(Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0)
(Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0)
(Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0)
(Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0)
(Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0)
(Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0)
(Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0)
(Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0)
(Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0)
(Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0)
(Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0)
(Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0)
(Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-9-2b6861506a11> in <module>()
----> 1 vgg = Vgg16()
      2 # Grab a few images at a time for training and validation.
      3 # NB: They must be in subdirectories named based on their category
      4 batches = vgg.get_batches(path+'train', batch_size=batch_size)
      5 val_batches = vgg.get_batches(path+'valid', batch_size=batch_size*2)

/Users/zhangdongyu/Desktop/Fast_ai/courses/deeplearning1/nbs/vgg16.pyc in __init__(self)
     41     def __init__(self):
     42         self.FILE_PATH = 'http://files.fast.ai/models/'
---> 43         self.create()
     44         self.get_classes()
     45 

/Users/zhangdongyu/Desktop/Fast_ai/courses/deeplearning1/nbs/vgg16.pyc in create(self)
    127         self.ConvBlock(3, 512)
    128 
--> 129         model.add(Flatten())
    130         self.FCBlock()
    131         self.FCBlock()

/Users/zhangdongyu/anaconda/lib/python2.7/site-packages/keras/models.pyc in add(self, layer)
    330                  output_shapes=[self.outputs[0]._keras_shape])
    331         else:
--> 332             output_tensor = layer(self.outputs[0])
    333             if isinstance(output_tensor, list):
    334                 raise TypeError('All layers in a Sequential model '

/Users/zhangdongyu/anaconda/lib/python2.7/site-packages/keras/engine/topology.pyc in __call__(self, x, mask)
    570         if inbound_layers:
    571             # This will call layer.build() if necessary.
--> 572             self.add_inbound_node(inbound_layers, node_indices, tensor_indices)
    573             # Outputs were already computed when calling self.add_inbound_node.
    574             outputs = self.inbound_nodes[-1].output_tensors

/Users/zhangdongyu/anaconda/lib/python2.7/site-packages/keras/engine/topology.pyc in add_inbound_node(self, inbound_layers, node_indices, tensor_indices)
    633         # creating the node automatically updates self.inbound_nodes
    634         # as well as outbound_nodes on inbound layers.
--> 635         Node.create_node(self, inbound_layers, node_indices, tensor_indices)
    636 
    637     def get_output_shape_for(self, input_shape):

/Users/zhangdongyu/anaconda/lib/python2.7/site-packages/keras/engine/topology.pyc in create_node(cls, outbound_layer, inbound_layers, node_indices, tensor_indices)
    168             # TODO: try to auto-infer shape
    169             # if exception is raised by get_output_shape_for.
--> 170             output_shapes = to_list(outbound_layer.get_output_shape_for(input_shapes[0]))
    171         else:
    172             output_tensors = to_list(outbound_layer.call(input_tensors, mask=input_masks))

/Users/zhangdongyu/anaconda/lib/python2.7/site-packages/keras/layers/core.pyc in get_output_shape_for(self, input_shape)
    474             raise ValueError('The shape of the input to "Flatten" '
    475                              'is not fully defined '
--> 476                              '(got ' + str(input_shape[1:]) + '. '
    477                              'Make sure to pass a complete "input_shape" '
    478                              'or "batch_input_shape" argument to the first '

ValueError: The shape of the input to "Flatten" is not fully defined (got (0, 7, 512). Make sure to pass a complete "input_shape" or "batch_input_shape" argument to the first layer in your model.

How can I solve it?

Were you able to solve this. I am running into same issue

Hi Vladimir, Did you get an answer on your question as I have the same question?

Regards,
Sanjay

Hey guys,

One thingy I see is that most of my friends are bugged about that almost half of the first lecture is about setting up. My suggestion is to split it into two videos and rename the first part, which is about setting up, Lecture 0.5. Also if splitting of the videos would be refilmed it would also enable you to change links (from platform.ai to files.fast.ai) of the files. I’d be more than happy to help you on this one.

1 Like


Theano and TensorFlow implement convolution in different ways
you have to convert the kernel before using it

I had written a post on Matrix Multiplication. It will give you an intuitive, no-math view of multiplication rules. I would love to hear your thoughts on it. https://kishorepv.github.io/Matrix-Multiplication/

from keras.models import load_model
model = load_model('my_model.h5')

See Keras documentation for details.

under the hood the implementation of VGG uses SVM(https://en.wikipedia.org/wiki/Support_vector_machine) to do the classification and regression analysis and calculate loss.

Could you please explain how SVM is related to VGG? I can’t find it in the paper.

1 Like

I was really confused what you are doing in finetune with this part:

for c in batches.class_indices:
    classes[batches.class_indices[c]] = c

The same thing can be achieved with just

sorted(classes, key=classes.get)

You wanted people to get confused right? :grinning:

I spent like an hour trying to figure out why it wasn’t working. Thought there was some error in the code. Thanks for this.

Have you had any luck with this error? I assumed it should have run right out of the box, but I guess between the time the course first launched and today, things have changed; the script doesn’t run as expected

When I run the code under ‘Create VGG model from scratch using Keras’ , I get a No JSON could be decoded error

I actually spent quite some time installing all the necessary libraries for 2.7 as I use 3.5

Also do you have access to platform.ai. I don’t see to have access

Same issue here. conda install bcolz seems to complete the installation fine but then when I run the code it seems to still not recognize the module bcolz

Hi Im having this error on initialising Vgg16()

Dimension 1 in both shapes must be equal, but are 2 and 1000 for ‘Assign_216’ (op: ‘Assign’) with input shapes: [4096,2], [4096,1000]

1 Like

I’m having some difficulty modifying lesson one to enter the Kaggle competition. I have the writing to a csv working, and I’ve trained the model on the data, but I’m unsure of how to apply that to the test data.

I put 6 test data files in the /test folder to give it a go, but I can’t figure out how to load them via vgg.get_batches.

test_batches = vgg.get_batches(path+'test', batch_size=batch_size)
print(os.listdir(path+'test'))
test_batches.filenames

Found 0 images belonging to 0 classes.
[‘5.jpg’, ‘3.jpg’, ‘6.jpg’, ‘2.jpg’, ‘4.jpg’, ‘7.jpg’]
Out[104]:
[]

I haven’t gotten there yet, but I also don’t see how I’m going to match the filename ID to the prediction just yet when .filenames gives everything, not just what is in the current batch - may have to make an iterator which gives the file name too.

Ah, the key was putting the files in another directory lower. They are now in /test/test, and the following output occurs:

Found 6 images belonging to 1 classes.

And I got it predicting!! Now just to get that paired back to the filename, and I can submit!!

I figured out that batch.filenames does actually give a list of the filenames in the order of the batching, so I ended up using that. YAAAAAY Thanks for the course Jeremy this is very awesome!!!

I am starting with lesson 1 and the Vgg16.py cloned from main git repository is leading to frustrating errors. I’ve searched for and implemented most of the instructions I could find from the forums &/ googling.

(OS : Ubuntu 16.04, GPU: 1080Ti)

Confirmed working GPU backend on Theano (0.9.0). Test code from Theano docs works & confirms gpu usage.
I have also set the .theanorc file appropriately.

Downgraded Keras from 2 to 1.1.0
Edited keras.json also as per the instructions I’ve collated.

Yet, vgg16.py is throwing atypical errors, with a full dump of something like os.env

['nvcc', '-shared', '-O3', '-Xlinker', '-rpath,/usr/local/cuda/lib64', '-arch=sm_61', '-m64', '-Xcompiler', '-fno-math-errno,-Wno-unused-label,-Wno-unused-variable,-Wno-write-strings,-DCUDA_NDARRAY_CUH=c72d035fdf91890f3b36710688069b2e,-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION,-fPIC,-fvisibility=hidden', '-Xlinker', '-rpath,/home/ra/.theano/compiledir_Linux-4.8--generic-x86_64-with-debian-stretch-sid-x86_64-2.7.13-64/cuda_ndarray', '-I/home/ravi/.theano/compiledir_Linux-4.8--generic-x86_64-with-debian-stretch-sid-x86_64-2.7.13-64/cuda_ndarray', '-I/usr/local/cuda/include', '-I/opt/anaconda/lib/python2.7/site-packages/theano/sandbox/cuda', '-I/opt/anaconda/lib/python2.7/site-packages/numpy/core/include', '-I/opt/anaconda/include/python2.7', '-I/opt/anaconda/lib/python2.7/site-packages/theano/gof', '-L/home/ra/.theano/compiledir_Linux-4.8--generic-x86_64-with-debian-stretch-sid-x86_64-2.7.13-64/cuda_ndarray', '-L/opt/anaconda/lib', '-o', '/home/ra/.theano/compiledir_Linux-4.8--generic-x86_64-with-debian-stretch-sid-x86_64-2.7.13-64/tmpRLFd51/ea4e203b6529466794536f8a1bfa77ae.so', 'mod.cu', '-lcudart', '-lcublas', '-lcuda_ndarray', '-lcudnn', '-lpython2.7']

Followed by a printout of some full C code.

Then, the Traceback points to exception in line 213 of vgg16.py
–> 213
validation_data=val_batches,nb_val_samples=val_batches.nb_sample)

And the Traceback ending with following Exception message:

Exception: ('The following error happened while compiling the node', GpuDnnConv{algo='small', inplace=True}(GpuContiguous.0, GpuContiguous.0, GpuAllocEmpty.0, GpuDnnConvDesc{border_mode='valid', subsample=(1, 1), conv_mode='conv', precision='float32'}.0, Constant{1.0}, Constant{0.0}), '\n', 'nvcc return status', 2, 'for cmd', 'nvcc -shared -O3 -Xlinker -rpath,/usr/local/cuda/lib64 -arch=sm_61 -m64 -Xcompiler -fno-math-errno,-Wno-unused-label,-Wno-unused-variable,-Wno-write-strings,-DCUDA_NDARRAY_CUH=c72d035fdf91890f3b36710688069b2e,-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION,-fPIC,-fvisibility=hidden -Xlinker -rpath,/home/ra/.theano/compiledir_Linux-4.8--generic-x86_64-with-debian-stretch-sid-x86_64-2.7.13-64/cuda_ndarray -I/home/ravi/.theano/compiledir_Linux-4.8--generic-x86_64-with-debian-stretch-sid-x86_64-2.7.13-64/cuda_ndarray -I/usr/local/cuda/include -I/opt/anaconda/lib/python2.7/site-packages/theano/sandbox/cuda -I/opt/anaconda/lib/python2.7/site-packages/numpy/core/include -I/opt/anaconda/include/python2.7 -I/opt/anaconda/lib/python2.7/site-packages/theano/gof -L/home/ravi/.theano/compiledir_Linux-4.8--generic-x86_64-with-debian-stretch-sid-x86_64-2.7.13-64/cuda_ndarray -L/opt/anaconda/lib -o /home/ravi/.theano/compiledir_Linux-4.8--generic-x86_64-with-debian-stretch-sid-x86_64-2.7.13-64/tmpRLFd51/ea4e203b6529466794536f8a1bfa77ae.so mod.cu -lcudart -lcublas -lcuda_ndarray -lcudnn -lpython2.7', "[GpuDnnConv{algo='small', inplace=True}(<CudaNdarrayType(float32, 4D)>, <CudaNdarrayType(float32, 4D)>, <CudaNdarrayType(float32, 4D)>, <CDataType{cudnnConvolutionDescriptor_t}>, Constant{1.0}, Constant{0.0})]")

This is frustrating as the enthusiasm to proceed with the lesson & learn real ML is curbed by all the troubleshooting that needs to be done. Please help me out to get started really.

You can use 4kdownloader to download from youtube for the lecture videos

It would be great to have a solution that does not violate youtube’s terms of service.

I ran into the same problem. I was trying to write code on my own.

from keras.models import Sequential
from keras.layers import Convolution2D, MaxPooling2D, ZeroPadding2D
from keras.layers import Activation, Dense, Dropout, Flatten, Lambda
import numpy as np

activation = 'relu'
model = Sequential()
model.add(Lambda(vgg_preprocess, input_shape=(3,224,224), output_shape=(3,224,224)))
model.add(ZeroPadding2D((1, 1, )))
model.add(Convolution2D(64, 3, 3,activation=activation, ))
model.add(ZeroPadding2D((1, 1, )))
model.add(Convolution2D(64, 3, 3,activation=activation, ))
model.add(MaxPooling2D((2, 2), strides=(2, 2)))
model.add(Flatten())

This ZeroPadding2D is imported from keras.layers. In the code given on the git, it is imported from keras.layers.convolutional. Both accept the different number of params.

I changed ZeroPadding2D((1, 1, ) to ZeroPadding2D((1, 1, 1, 1) and it worked.

To debug just comment the lines before flatten and see which causes the error.
Compare your model.summary() with summary supplied in git.