I wish to extract features from all the frames from a video in sumMe dataset. The frames of the video are generated using MATLAB and stored in .mat file which I am loading in python. I am trying to reshape blob size for the frame to fit in. Here is the code that I have written:
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
import caffe
import
scipy.io as sio
import sys
vidName = sys.argv[1]
directory = '../framesSumMe/'
net = caffe.Net('deploy3.prototxt','bvlc_alexnet.caffemodel',caffe.TEST)
data = sio.loadmat(directory + vidName +'Frames.mat')
transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape})
transformer.set_mean('data', np.load('python/caffe/imagenet/ilsvrc_2012_mean.npy').mean(1).mean(1))
transformer.set_transpose('data', (2,0,1))
transformer.set_channel_swap('data', (2,1,0))
transformer.set_raw_scale('data', 255.0)
net.blobs['data'].reshape(1,3,int(data['width']),int(data['height']))
features = dict()
temp = np.zeros((data['frCount'][0][0],4096));
features['frCount']=data['frCount'][0][0]
for i in range(0,data['frCount'][0][0]):
#load the image in the data layer
im = data['allFrames'][:,:,:,i]
net.blobs['data'].data[...] = transformer.preprocess('data', im)
out = net.forward_all(data=np.asarray([transformer.preprocess('data', im)]))
temp[0:4095][i] = net.blobs['fc6'].data.copy()
features['allFeatures']=temp
sio.savemat(directory + vidName +'Features',features)
When I run the code with the name of the .mat file as runtime argument I get an error saying "ValueError: could not broadcast input array from shape (3,227,227) into shape (1,3,320,240) " for the line net.blobs['data'].data[...] = transformer.preprocess('data', im). I do not get any error when I use the default value of 227 for height and width of the blob.
Kindly point out where is the mistake.