Meta2032系統(tǒng)開發(fā)(開發(fā)案例)及源碼方案
元宇宙是由虛擬現(xiàn)實(shí)、增強(qiáng)現(xiàn)實(shí)和互聯(lián)網(wǎng)相結(jié)合創(chuàng)造的沉浸式數(shù)字世界。元宇宙的內(nèi)涵及關(guān)鍵技術(shù)要求進(jìn)一步打破時(shí)空限制(5G和物聯(lián)網(wǎng)),真實(shí)沉浸感(VR),價(jià)值的傳遞(Web 3.0、區(qū)塊鏈)。此前,IDC還繪制了元宇宙涵蓋的技術(shù)概念。
元宇宙既包含數(shù)字經(jīng)濟(jì)中的5G、人工智能、區(qū)塊鏈、云計(jì)算、大數(shù)據(jù),也融合了對(duì)VR、AR、腦機(jī)接口、物聯(lián)網(wǎng)等技術(shù)的前瞻布局。發(fā)展元宇宙,關(guān)鍵在于大力提升自主創(chuàng)新能力,突破關(guān)鍵核心技術(shù),實(shí)現(xiàn)高質(zhì)量發(fā)展。
import torch
import os
from transformers import BertTokenizer
import onnxruntime as ort
import numpy as np
GPU_IDS='-1'#模型格式轉(zhuǎn)換可以不用GPU
model,device=load_model_and_parallel(model,GPU_IDS,CKPT_PATH)
#CKPT_PATH是訓(xùn)練好的bert模型pt文件的地址
model.eval()
tokenizer=BertTokenizer('vocab.txt')#bert詞表
with torch.no_grad():開發(fā)I35源碼7O98案例O7I8
sen='今天天氣很好'
關(guān)于區(qū)塊鏈項(xiàng)目技術(shù)開發(fā)唯:MrsFu123,代幣發(fā)行、dapp智能合約開發(fā)、鏈游開發(fā)、多鏈錢包開發(fā)
交易所開發(fā)、量化合約開發(fā)、互助游戲開發(fā)、Nft數(shù)字藏品開發(fā)、眾籌互助開發(fā)、元宇宙開發(fā)、swap開發(fā)、
鏈上合約開發(fā)、ido開發(fā)、商城開發(fā)等,開發(fā)過各種各樣的系統(tǒng)模式,更有多種模式、制度、案例、后臺(tái)等,成熟技術(shù)團(tuán)隊(duì),歡迎實(shí)體參考。
sent_tokens=fine_grade_tokenize(sen,tokenizer)
encode_dict=tokenizer.encode_plus(text=sent_tokens,
max_length=MAX_SEQ_LEN,
is_pretokenized=True,
pad_to_max_length=True,
return_tensors='pt',
return_token_type_ids=True,
return_attention_mask=True)
samples={'token_ids':encode_dict['input_ids'],
'attention_masks':encode_dict['attention_masks'],
'token_type_ids':encode_dict['token_type_ids']}
for sample in samples:
samples[sample]=samples[sample].to(device)
output1,output2=model(**samples)#模型輸出可能有多個(gè),此處假設(shè)有兩個(gè)
def fine_grade_tokenize(raw_text,tokenizer):
"""
序列標(biāo)注任務(wù)BERT分詞器可能會(huì)導(dǎo)致標(biāo)注偏移,
用char-level來(lái)tokenize
"""
tokens=[]
for _ch in raw_text:
if _ch in['','t','n']:
tokens.append('[BLANK]')
else:
if not len(tokenizer.tokenize(_ch)):
tokens.append('[INV]')
else:
tokens.append(_ch)
return tokens
def load_model_and_parallel(model,gpu_ids,ckpt_path=None,strict=True):
"""
加載模型&放置到GPU中(單卡/多卡)
"""
gpu_ids=gpu_ids.split(',')
#set to device to the first cuda
device=torch.device("cpu"if gpu_ids[0]=='-1'else"cuda:"+gpu_ids[0])
if ckpt_path is not None:
logger.info(f'Load ckpt from{ckpt_path}')
model.load_state_dict(torch.load(ckpt_path,map_location=torch.device('cpu')),strict=strict)
model.to(device)
if len(gpu_ids)>1:
logger.info(f'Use multi gpus in:{gpu_ids}')
gpu_ids=[int(x)for x in gpu_ids]
model=torch.nn.DataParallel(model,device_ids=gpu_ids)
else:
logger.info(f'Use single gpu in:{gpu_ids}')
return model,device