本文整理汇总了Python中FileIO.save方法的典型用法代码示例。如果您正苦于以下问题:Python FileIO.save方法的具体用法?Python FileIO.save怎么用?Python FileIO.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileIO
的用法示例。
在下文中一共展示了FileIO.save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: saveCenters
# 需要导入模块: import FileIO [as 别名]
# 或者: from FileIO import save [as 别名]
def saveCenters(doOnlyFulls = False, trainingFolder = '../data/nicicon/csv/train/csv/' , suffix = '_train.csv', savePath = '../data/newMethodTraining/allCentersNic.csv'):
"""This file computes representatives of classes in the nicicon database and saves it to the ./data/csv/allCentersNic.csv"""
files = ['accident','bomb','car','casualty','electricity','fire','firebrigade','flood','gas','injury','paramedics', 'person', 'police','roadblock']
centerSet = []
my_names = []
my_isFull = []
f = FileIO()
extr_train = Extractor(trainingFolder)
train_features, \
train_isFull, \
train_classId, \
train_names = extr_train.loadniciconfolders()
for mfile in files[:]:
#Get every instance in the given class
names, isFull, features = f.load(trainingFolder + mfile + '/' + mfile + suffix)
#Initialise centers as 0
nowCenter = np.zeros(len(features[0]))
if not doOnlyFulls:
#Use every full and partial instance in the class and sum them
totalNumOfInstances = len(features)
for instance in features:
nowCenter += instance
else:
#Use only full instances in the class and sum them
totalNumOfInstances = 0
for i in range(len(features)):
if isFull[i] == True:#Check the prints to see if this works fine (See if the totalNumOfInstances is meaningful
nowCenter+=features[i]
totalNumOfInstances+=1
print mfile,'Used ', totalNumOfInstances, 'of instances to find the class center'
nowCenter = nowCenter/totalNumOfInstances
centerSet.append(nowCenter)#Add the mean feature vector for this representative
my_names.append(mfile)#The name of the representative
my_isFull.append(0)#Just set anything, not necessary for class representative
f.save(my_isFull,my_names,centerSet,savePath)
示例2: saveCenters
# 需要导入模块: import FileIO [as 别名]
# 或者: from FileIO import save [as 别名]
def saveCenters(doOnlyFulls = True, getDataFrom = '../data/csv/', numClass =10 ** 6, savePath = '../data/newMethodTraining/allCenters.csv'):
"""This file computes centers of classes in the eitz database and saves it to savePath"""
files = ['airplane', 'alarm-clock', 'angel', 'ant', 'apple', 'arm', 'armchair', 'ashtray', 'axe',
'backpack', 'banana', 'barn', 'baseball-bat', 'basket', 'bathtub', 'bear-(animal)', 'bed',
'bee', 'beer-mug', 'bell', 'bench', 'bicycle', 'binoculars', 'blimp', 'book', 'bookshelf',
'boomerang', 'bottle-opener', 'bowl', 'brain', 'bread', 'bridge', 'bulldozer', 'bus', 'bush',
'butterfly', 'cabinet', 'cactus', 'cake', 'calculator', 'camel', 'camera', 'candle', 'cannon',
'canoe', 'car-(sedan)', 'carrot', 'castle', 'cat', 'cell-phone', 'chair', 'chandelier',
'church', 'cigarette', 'cloud', 'comb', 'computer-monitor', 'computer-mouse', 'couch', 'cow',
'crab', 'crane-(machine)', 'crocodile', 'crown', 'cup', 'diamond', 'dog', 'dolphin', 'donut',
'door', 'door-handle', 'dragon', 'duck', 'ear', 'elephant', 'envelope', 'eye', 'eyeglasses',
'face', 'fan', 'feather', 'fire-hydrant', 'fish', 'flashlight', 'floor-lamp', 'flower-with-stem',
'flying-bird', 'flying-saucer', 'foot', 'fork', 'frog', 'frying-pan', 'giraffe', 'grapes',
'grenade', 'guitar', 'hamburger', 'hammer', 'hand', 'harp', 'hat', 'head', 'head-phones',
'hedgehog', 'helicopter', 'helmet', 'horse', 'hot-air-balloon', 'hot-dog', 'hourglass',
'house', 'human-skeleton', 'ice-cream-cone', 'ipod', 'kangaroo', 'key', 'keyboard', 'knife',
'ladder', 'laptop', 'leaf', 'lightbulb', 'lighter', 'lion', 'lobster', 'loudspeaker',
'mailbox', 'megaphone', 'mermaid', 'microphone', 'microscope', 'monkey', 'moon', 'mosquito',
'motorbike', 'mouse-(animal)', 'mouth', 'mug', 'mushroom', 'nose', 'octopus', 'owl',
'palm-tree', 'panda', 'paper-clip', 'parachute', 'parking-meter', 'parrot', 'pear', 'pen',
'penguin', 'person-sitting', 'person-walking', 'piano', 'pickup-truck', 'pig', 'pigeon',
'pineapple', 'pipe-(for-smoking)', 'pizza', 'potted-plant', 'power-outlet', 'present',
'pretzel', 'pumpkin', 'purse', 'rabbit', 'race-car', 'radio', 'rainbow', 'revolver',
'rifle', 'rollerblades', 'rooster', 'sailboat', 'santa-claus', 'satellite', 'satellite-dish',
'saxophone', 'scissors', 'scorpion', 'screwdriver', 'sea-turtle', 'seagull', 'shark',
'sheep', 'ship', 'shoe', 'shovel', 'skateboard', 'skull', 'skyscraper', 'snail', 'snake',
'snowboard', 'snowman', 'socks', 'space-shuttle', 'speed-boat', 'spider', 'sponge-bob',
'spoon', 'squirrel', 'standing-bird', 'stapler', 'strawberry', 'streetlight', 'submarine',
'suitcase', 'sun', 'suv', 'swan', 'sword', 'syringe', 't-shirt', 'table', 'tablelamp',
'teacup', 'teapot', 'teddy-bear', 'telephone', 'tennis-racket', 'tent', 'tiger', 'tire',
'toilet', 'tomato', 'tooth', 'toothbrush', 'tractor', 'traffic-light', 'train', 'tree',
'trombone', 'trousers', 'truck', 'trumpet', 'tv', 'umbrella', 'van', 'vase', 'violin',
'walkie-talkie', 'wheel', 'wheelbarrow', 'windmill', 'wine-bottle', 'wineglass', 'wrist-watch',
'zebra']
centerSet = []
my_names = []
my_isFull = []
f = FileIO()
#Set number of classes to find centers
if(numClass == None):
numClass = len(files)
else:
numClass = min(numClass, len(files))
for mfile in files[:numClass]:
#Get every instance in the given class
names, isFull, features = f.load(getDataFrom + mfile + '/' + mfile + '.csv')
#Initialise centers as 0
nowCenter = np.zeros(len(features[0]))
if not doOnlyFulls:
#Use every full and partial instance in the class and sum them
totalNumOfInstances = len(features)
for instance in features:
nowCenter += instance
else:
#Use only full instances in the class and sum them
totalNumOfInstances = 0
for i in range(len(features)):
if isFull[i] == True:#Check the prints to see if this works fine (See if the totalNumOfInstances is meaningful
nowCenter+=features[i]
totalNumOfInstances+=1
print mfile,'Used ', totalNumOfInstances, 'of instances to find the class center'
nowCenter = nowCenter/totalNumOfInstances
centerSet.append(nowCenter)#Add the mean feature vector for this representative
my_names.append(mfile)#The name of the representative
my_isFull.append(0)#Just set anything, not necessary for class representative
f.save(my_isFull,my_names,centerSet,savePath)