python生成pkl文件(pkl文件的读取和写入)

我在训练UCF101数据集的时候,遇到一个大高玩使用pkl文件,一开始使用它们的数据炮的好好的。后来开始跑自己的数据时,就出问题了。不知道这个pkl到底是个什么东西。

原始的那个大高玩的ucf101的标签数据读取出来是这个样的:

['PommelHorse', 'Surfing', 'HammerThrow', 'PlayingViolin', 'WallPushups', 
'PullUps', 'PizzaTossing', 'SalsaSpin', 'Shotput', 'CricketShot', 'HorseRiding', 'CliffDiving', 'Rowing', 'BenchPress', 'SkyDiving', 'BaseballPitch', 'Lunges', 'Haircut', 'JumpRope', 'Kayaking', 'GolfSwing', 'FrontCrawl', 'Bowling', 
'RopeClimbing', 'BoxingSpeedBag', 'ShavingBeard', 'Swing', 'RockClimbingIndoor', 'ParallelBars', 'Fencing', 'Diving', 'TrampolineJumping', 'PlayingDhol', 
'ApplyEyeMakeup', 'HandstandWalking', 'BandMarching', 'Skijet', 'BrushingTeeth', 'Billiards', 'LongJump', 'TennisSwing', 'BreastStroke', 'Mixing', 
'TableTennisShot', 'Punch', 'VolleyballSpiking', 'PlayingCello', 'JugglingBalls', 'ApplyLipstick', 'Rafting', 'Hammering', 'BalanceBeam', 'Knitting', 'Drumming', 'HighJump', 'PlayingTabla', 'BodyWeightSquats', 'PlayingPiano', 
'HandstandPushups', 'TaiChi', 'Typing', 'SoccerPenalty', 'JavelinThrow', 
'PlayingDaf', 'Biking', 'CricketBowling', 'BlowingCandles', 'SkateBoarding', 'SoccerJuggling', 'BasketballDunk', 'CleanAndJerk', 'HeadMassage', 
'FloorGymnastics', 'SumoWrestling', 'BabyCrawling', 'HulaHoop', 
'FieldHockeyPenalty', 'MoppingFloor', 'Skiing', 'BlowDryHair', 'PoleVault', 'Basketball', 'MilitaryParade', 'PushUps', 'HorseRace', 'PlayingSitar',
 'WalkingWithDog', 'PlayingGuitar', 'StillRings', 'UnevenBars', 'Archery', 
 'BoxingPunchingBag', 'CuttingInKitchen', 'ThrowDiscus', 'Nunchucks', 
 'WritingOnBoard', 'YoYo', 'PlayingFlute', 'IceDancing', 'FrisbeeCatch', 
 'JumpingJack']

如果我们想训练自己的数据,肯定也要按照这个格式自己创建一个pkl格式的标签,没办法啊,谁让咱不会自己搭建完整的框架呢。

不多比比,直接开始

写入pkl

data = ["label1", "label2", "label3", "label4",, "label_i"]
with open("D:/Program Files/pycharm files/JE_Bi-LSTM_CRF/data_path/这边填你的保存路径/medicine.pkl", "wb") as f:
    pickle.dump(data, f)

读取pkl

    fr = open("D:/Program Files/pycharm files/JE_Bi-LSTM_CRF/data_path/这边填你的保存路径/medicine.pkl",'rb')# open的参数是pkl文件的路径
    inf = pickle.load(fr)  # 读取pkl文件的内容
    print(inf)
    fr.close()

就是这么简单

你可能感兴趣的:(Pytorch,python)