# ### Load feature extractor neural network if not load_features: vnet = load_verbatimnet('fc7', paramsfile=paramsfile) vnet.compile(loss='mse', optimizer='sgd') # ### Image features # # Currently taken as averages of all shard features in the image. You can either load them or extract everything manually, depending on if you have the .npy array. if load_features: print "Loading features in from " + featurefile imfeats = np.load(featurefile) print "Loaded features" else: print "Begin extracting features from " + hdf5images imfeats = extract_imfeats(hdf5images, vnet, steps=(5, 5), varthresh=0.05) print h5py.File(hdf5images).keys() np.save(featurefile, imfeats) # ### Build classifier imfeats = (imfeats.T / np.linalg.norm(imfeats, axis=1)).T F = imfeats.dot(imfeats.T) np.fill_diagonal(F, -1) # ### Evaluate classifier on HDF5 file (ICDAR 2013) # Top k (soft criteria) k = 10 # Max top (hard criteria) maxtop = 2
vnet = load_verbatimnet('fc7', paramsfile=paramsfile) vnet.compile(loss='mse', optimizer='sgd') ### Image features # Currently taken as averages of all shard features in the image. You can either load them or extract everything manually, depending on if you have the .npy array. if load_features: print "Loading features in from " + featurefile imfeats = np.load(featurefile) print "Loaded features" else: print "Begin extracting features from " + hdf5images noiseparamfile = '/work/code/repo/models/conv2_linet_iam-bin.hdf5' imfeats = extract_imfeats( hdf5images, vnet, denoiser=load_denoisenet(noiseparams=noiseparamfile), outdir=outdir, steps=(5, 5), compthresh=250) print h5py.File(hdf5images).keys() np.save(featurefile, imfeats) # ### Build classifier imfeats = (imfeats.T / np.linalg.norm(imfeats, axis=1)).T F = imfeats.dot(imfeats.T) np.fill_diagonal(F, -1) ### Evaluate classifier on HDF5 file (ICDAR 2013) # Top k (soft criteria) k = 10 # Max top (hard criteria)
# ### Load feature extractor neural network if not load_features: vnet = load_verbatimnet( 'fc7', paramsfile=paramsfile ) vnet.compile(loss='mse', optimizer='sgd') ### Image features # Currently taken as averages of all shard features in the image. You can either load them or extract everything manually, depending on if you have the .npy array. if load_features: print "Loading features in from "+featurefile imfeats = np.load(featurefile) print "Loaded features" else: print "Begin extracting features from "+hdf5images noiseparamfile = '/work/code/repo/models/conv2_linet_iam-bin.hdf5' imfeats = extract_imfeats(hdf5images, vnet, denoiser=load_denoisenet(noiseparams=noiseparamfile), outdir=outdir, steps=(5,5), compthresh=250 ) print h5py.File(hdf5images).keys() np.save( featurefile, imfeats ) # ### Build classifier imfeats = ( imfeats.T / np.linalg.norm( imfeats, axis=1 ) ).T F = imfeats.dot(imfeats.T) np.fill_diagonal( F , -1 ) ### Evaluate classifier on HDF5 file (ICDAR 2013) # Top k (soft criteria) k = 10 # Max top (hard criteria) maxtop = 3
if not load_features: vnet = load_verbatimnet( 'fc7', paramsfile=paramsfile ) vnet.compile(loss='mse', optimizer='sgd') # ### Image features # # Currently taken as averages of all shard features in the image. You can either load them or extract everything manually, depending on if you have the .npy array. if load_features: print "Loading features in from "+featurefile imfeats = np.load(featurefile) print "Loaded features" else: print "Begin extracting features from "+hdf5images imfeats = extract_imfeats( hdf5images, vnet, steps=(5,5), varthresh=0.05 ) print h5py.File(hdf5images).keys() np.save( featurefile, imfeats ) # ### Build classifier imfeats = ( imfeats.T / np.linalg.norm( imfeats, axis=1 ) ).T F = imfeats.dot(imfeats.T) np.fill_diagonal( F , -1 ) # ### Evaluate classifier on HDF5 file (ICDAR 2013) # Top k (soft criteria) k = 10