[英]How I can find out how many vectors are processed in Python?
I have a very long dictionary containing more than 1 million keys.我有一本很长的字典,其中包含超过 100 万个键。
df['file'] = files
df['features'] = df.apply(lambda row: getVector(model, row['file']), axis=1)
Below is getVector function:下面是 getVector 函数:
vector=model.predict(inp.reshape(1, 100, 100, 1))
print(file+ " is added.")
return vector
But, it shows blahblah.jpg is added but it has no use as I do not know how many files have been processed.但是,它显示添加了 blahblah.jpg 但它没有用,因为我不知道已经处理了多少文件。 My question is that how I get the count of files that has been processed?
我的问题是如何获得已处理的文件数?
For example,例如,
1200 out of 1,000,000 is processed.
1,000,000 个中的 1200 个被处理。
or even just甚至只是
1200
1200
I do not want to have a neat and clean output.我不想有一个整洁干净的输出。 I just want to know how many files have been processed.
我只想知道处理了多少文件。
Any idea would be appreciated.任何想法将不胜感激。
How about creating a column in the initial dataframe with incremental numbers?如何在初始数据框中用增量数字创建一列? You would use this column as an input of your getVector function and display the value.
您可以将此列用作 getVector 函数的输入并显示值。 Something like this:
像这样的东西:
df['features'].apply(lambda row: getVector(model, row['file'], row['count']), axis=1)
You can use a decorator to count it:您可以使用装饰器来计算它:
import functools
def count(func):
@functools.wraps(func)
def wrappercount(*args):
func(*args)
func.counter+=1
print(func.counter,"of 1,000,000 is processed.")
func.counter=0
return wrappercount
@count
def getVector(*args):
#write code and add arguments
Learn more about decorators here .在此处了解有关装饰器的更多信息。
If you're having a class of which you want to count a method's usage, you can use the following:如果您有一个要计算方法使用情况的类,可以使用以下命令:
class getVector:
counter=0
def __init__(self):#add your arguments here
#write code here
getVector.counter +=1
print(getVector.counter,"of 1,000,000 is processed.")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.