#================================================
# Preprocessing
#================================================

print("======Loading and Preprocessing...======")
start_time = time.time()

#If path to image passed as argument load and process that image, otherwise load from annotations(evaluation images)
if (len(sys.argv) > 3):
    imdb = [
        il.loadAndPreProcessSingle(str(sys.argv[3]), scaleFactor,
                                   (windowSize, windowSize))
    ]
else:
    imdb = il.loadAndPreProcessIms('annotations_short.txt', scaleFactor,
                                   (windowSize, windowSize))

print("Image database: {0} images".format(len(imdb)))
[X, Y, W] = il.getCNNFormat(imdb, stepSize, windowSize)
print("finished preprocessing in {0}".format(time.time() - start_time))

print("=========================================")
#================================================
# 12 net
#================================================

print("\n\n============== 12Net ====================")
model12 = model_architecture.setUp12net(windowSize)
print("Loading model from: " + model12FileName)
model12.load_weights(model12FileName)
stepSize = 24
T12 = 0 #threshold for it is passed to 48net
T48 = 0 #threshold for if it is a high label for the final evaluation

#================================================
# Preprocessing
#================================================

print("======Loading and Preprocessing...======")
start_time = time.time()

#If path to image passed as argument load and process that image, otherwise load from annotations(evaluation images)
if (len(sys.argv) > 3):
        imdb =[il.loadAndPreProcessSingle(str(sys.argv[3]), scaleFactor, (windowSize, windowSize))]
else:
    imdb = il.loadAndPreProcessIms('annotations_test_short.txt', scaleFactor, (windowSize,windowSize))

print("Image database: {0} images".format(len(imdb)))
[X, Y, W] = il.getCNNFormat(imdb, stepSize, windowSize)
print("finished preprocessing in {0}".format(time.time()-start_time))

print("=========================================")
#================================================
# 12 net
#================================================

print("\n\n============== 12Net ====================")
model12 = model_architecture.setUp12net(windowSize)
print("Loading model from: " + model12FileName)
model12.load_weights(model12FileName)
## Load data for processing and then send into first net
# If preprocessed files exists (data path passed as argument) load the raw data
if (len(sys.argv) > 1):
    print("======Loading data from file...======")
    start_time = time.time()
    data_path = str(sys.argv[1])
    X = np.load(data_path + '_X.npy')
    Y = np.load(data_path + '_Y.npy')
    W = np.load(data_path + '_W.npy')
    print("finished loading in {0}".format(time.time() - start_time))
# Otherwise load images and preprocess
else:
    print("======Loading and Preprocessing...======")
    start_time = time.time()
    imdb = il.loadAndPreProcessIms('annotations_train.txt', scaleFactor,
                                   (prevWindowSize, prevWindowSize))
    imdb2 = il.loadAndPreProcessNegative(
        'images/sun2', 300, 2, (prevWindowSize * 4, prevWindowSize * 4))
    imdb = imdb + imdb2
    random.shuffle(imdb)

    [X, Y, W] = il.getCNNFormat(imdb, stepSize, prevWindowSize)
    np.save('data/data_X', X)
    np.save('data/data_Y', Y)
    np.save('data/data_W', W)
    print("finished preprocessing in {0}".format(time.time() - start_time))

print("X-shape: {0}".format(X.shape))
print("Y-shape: {0}".format(Y.shape))

[X_48, Y_48, W_48, windowSize,
예제 #4
0
nbEpoch = 10
modelFileName = '12_trained_model_w' + str(windowSize) + '_scale' + str(scaleFactor) + '_step' + str(stepSize) + '.h5'
# If preprocessed files exists (data path passed as argument) load the raw data
if (len(sys.argv) > 1):
    print("======Loading data from file...======")
    start_time = time.time()
    data_path = str(sys.argv[1])
    X = np.load(data_path + '_X.npy')
    Y = np.load(data_path + '_Y.npy')
    W = np.load(data_path + '_W.npy')
    print("finished loading in {0}".format(time.time()-start_time))
# Otherwise load images and preprocess
else:
    print("======Loading and Preprocessing...======")
    start_time = time.time()
    imdb = il.loadAndPreProcessIms('annotations_train.txt', scaleFactor, (windowSize*4,windowSize*4))
    imdb2 = il.loadAndPreProcessNegative('images/sun2',300,2, (windowSize*4, windowSize*4))
    imdb = imdb + imdb2
    random.shuffle(imdb)
    print("getting cnn format")
    [X, Y, W] = il.getCNNFormat(imdb, stepSize, windowSize)
    np.save('data/data_X',X)
    np.save('data/data_Y',Y)
    np.save('data/data_W',W)
    print("finished preprocessing in {0}".format(time.time()-start_time))


print("X-shape: {0}".format(X.shape))
print("Y-shape: {0}".format(Y.shape))

history = train.train12Net(X,Y, windowSize, scaleFactor, stepSize, batchSize, nbEpoch)
예제 #5
0
stepSize = 24
scaleFactor = 2
batchSize = 1

#================================================
# Preprocessing
#================================================

print("======Loading and Preprocessing...======")
start_time = time.time()

#If path to image passed as argument load and process that image, otherwise load from annotations(evaluation images)
if (len(sys.argv) > 2):
        imdb =[il.loadAndPreProcessSingle(str(sys.argv[2]), scaleFactor, (windowSize12*4, windowSize12*4))]
else:
    imdb = il.loadAndPreProcessIms('annotations_short.txt', scaleFactor, (windowSize12*4,windowSize12*4))

print("Image database: {0} images".format(len(imdb)))
[X, Y, W] = il.getCNNFormat(imdb, stepSize, windowSize12)
print("finished preprocessing in {0}".format(time.time()-start_time))
print('X-shape')
print(X.shape)
print('Y-shape: ')
print(Y.shape)
print('W-shape')
print(W.shape)

#Load model
model48 = model_architecture.setUp48net(windowSize48)
print("Loading model from: " + model48FileName)
model48.load_weights(model48FileName)