Example #1
0

def getCodeLengthMatch(numChars, goldNumChars):
    minLen = min(len(codes), len(goldCodes))
    return np.count_nonzero(numChars[0:minLen] == goldNumChars[0:minLen])


def getCodeMatchScore(codes, goldCodes):
    totScore = 0
    for i in range(min(len(codes), len(goldCodes))):
        totScore += getLCS(codes[i], goldCodes[i]) / len(goldCodes[i])
    return totScore


numTest = 2000
filepaths = ["test/image%d.png" % (i) for i in range(numTest)]
file = open("test/codes.txt", "r")
goldCodes = file.read().splitlines()
file.close()
goldNumChars = np.array([len(goldCodes[i]) for i in range(len(goldCodes))])

# Get recommendations from predict.py and time the thing
tic = tm.perf_counter()
(numChars, codes) = predict.decaptcha(filepaths)
toc = tm.perf_counter()

print("Total time taken is %.6f seconds " % (toc - tic))
print("Fraction of code lengths that match is %.6f" %
      (getCodeLengthMatch(numChars, goldNumChars) / numTest))
print("Code match score is %.6f" %
      (getCodeMatchScore(codes, goldCodes) / numTest))
Example #2
0
# these were predictions on the first 90 test points and evaluate accordingly


def getCodeLengthMatch(numChars, goldNumChars):
    minLen = min(len(codes), len(goldCodes))
    return np.count_nonzero(numChars[0:minLen] == goldNumChars[0:minLen])


def getCodeMatchScore(codes, goldCodes):
    totScore = 0
    for i in range(min(len(codes), len(goldCodes))):
        totScore += getLCS(codes[i], goldCodes[i]) / len(goldCodes[i])
    return totScore


numTest = int(sys.argv[1])
file = open("codes.txt", "r")
goldCodes = file.read().splitlines()
file.close()
goldNumChars = np.array([len(goldCodes[i]) for i in range(len(goldCodes))])

# Get recommendations from predict.py and time the thing
# tic = tm.perf_counter()
(numChars, codes) = predict.decaptcha()
# toc = tm.perf_counter()

# print( "Total time taken is %.6f seconds " % (toc - tic) )
print("Fraction of code lengths that match is %.6f\n" %
      (getCodeLengthMatch(numChars, goldNumChars) / numTest))
print("Code match score is %.6f\n" %
      (getCodeMatchScore(codes, goldCodes) / numTest))