本文整理汇总了Python中PyTorch.getGlobalState方法的典型用法代码示例。如果您正苦于以下问题:Python PyTorch.getGlobalState方法的具体用法?Python PyTorch.getGlobalState怎么用?Python PyTorch.getGlobalState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyTorch
的用法示例。
在下文中一共展示了PyTorch.getGlobalState方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
# 需要导入模块: import PyTorch [as 别名]
# 或者: from PyTorch import getGlobalState [as 别名]
def save(filepath, target):
lua = PyTorch.getGlobalState().getLua()
topStart = lua.getTop()
pushGlobal(lua, 'torch', 'saveobj')
pushSomething(lua, filepath)
pushSomething(lua, target)
res = lua.pcall(2, 0, 1)
if res != 0:
errorMessage = popString(lua)
raise Exception(errorMessage)
topEnd = lua.getTop()
assert topStart == topEnd
示例2: __init__
# 需要导入模块: import PyTorch [as 别名]
# 或者: from PyTorch import getGlobalState [as 别名]
def __init__(self, nameList, *args):
lua = PyTorch.getGlobalState().getLua()
self.__dict__['__objectId'] = getNextObjectId()
topStart = lua.getTop()
pushGlobalFromList(lua, nameList)
for arg in args:
pushSomething(lua, arg)
# print('nameList', nameList)
# print('args', args)
res = lua.pcall(len(args), 1)
if res != 0:
errorMessage = popString(lua)
raise Exception(errorMessage)
# lua.call(len(args), 1)
registerObject(lua, self)
topEnd = lua.getTop()
assert topStart == topEnd
示例3: load
# 需要导入模块: import PyTorch [as 别名]
# 或者: from PyTorch import getGlobalState [as 别名]
def load(filepath):
lua = PyTorch.getGlobalState().getLua()
topStart = lua.getTop()
pushGlobal(lua, 'torch', 'loadobj')
pushSomething(lua, filepath)
res = lua.pcall(1, 1, 1)
if res != 0:
errorMessage = popString(lua)
raise Exception(errorMessage)
res = popSomething(lua)
topEnd = lua.getTop()
assert topStart == topEnd
return res
示例4: __init__
# 需要导入模块: import PyTorch [as 别名]
# 或者: from PyTorch import getGlobalState [as 别名]
def __init__(self, nameList, *args):
lua = PyTorch.getGlobalState().getLua()
self.__dict__['__objectId'] = getNextObjectId()
topStart = lua.getTop()
pushGlobalFromList(lua, nameList)
for arg in args:
if isinstance(arg, int):
lua.pushNumber(arg)
else:
raise Exception('arg type ' + str(type(arg)) + ' not implemented')
lua.call(len(args), 1)
registerObject(lua, self)
# nameList = nameList[:]
# nameList.append('float')
# pushGlobalFromList(lua, nameList)
# pushObject(lua, self)
# lua.call(1, 0)
topEnd = lua.getTop()
assert topStart == topEnd
示例5: interruptableCall
# 需要导入模块: import PyTorch [as 别名]
# 或者: from PyTorch import getGlobalState [as 别名]
from __future__ import print_function
import threading
import PyTorch
import PyTorchLua
import PyTorchHelpers
lua = PyTorch.getGlobalState().getLua()
# this is so we can ctrl-c lua functions. we have to run them in a separate thread
# for this, so that the python event log can continue ('event loop' might not be quite
# the right technical term, but the concept is approximately right. I think)
def interruptableCall(function, args):
mythread = threading.Thread(target=function, args = args)
mythread.daemon = True
mythread.start()
while mythread.isAlive():
mythread.join(0.1)
#print('join timed out')
nextObjectId = 1
def getNextObjectId():
global nextObjectId
res = nextObjectId
nextObjectId += 1
return res
def pushGlobal(lua, name1, name2=None, name3=None):
lua.getGlobal(name1)
if name2 is None:
return
lua.getField(-1, name2)