在下面的代码中,当我打印它时,conv_out.get_shape()它会给我输出(1,14,14,1)。我想将第二个第三个和第四个维度相乘(14*14*1)。我怎样才能做到这一点?
input = tf.Variable(tf.random_normal([1,28,28,1]))
filter = tf.Variable(tf.random_normal([5,5,1,1]))
def conv2d(input,filter):
return tf.nn.conv2d(input,filter,strides=[1,2,2,1],padding='SAME')
conv_out = conv2d(input,filter)
sess = tf.InteractiveSession()
sess.run(tf.initialize_all_variables())
print conv_out.get_shape()
print conv_out.get_shape().as_list()[2]
Run Code Online (Sandbox Code Playgroud) 我目前正在x86程序集中编写一个简单的程序,它将数据获取到任意内存地址并以十六进制形式打印到终端.它正在NASM 2.12.02中组装,我正在使用bochs 2.6.8运行生成的bin.我写了一个调用的程序print_hex.asm,它使用db定义的ASCII字符的指数,如下图所示.
ascii_table: db "0123456789ABCDEF"
组装完整程序并运行结果时,同一行
(an increasing number)i[CPU0 ] MOV_EwSw: using of nonexisting segment register 7
再次打印到终端,前面是一个不断增加的数字.奇怪的是,如果我将线路更改为
ascii_table: db "0123456789ABC"
通过简单地省略字符串的最后三个字母,它工作正常(虽然组装的程序在尝试转换D,E或F的十六进制值时会收到运行时错误)
这里发生了什么?我不允许连续声明这么多数据吗?NASM对我不屑一顾吗?
编辑:请参阅下面的完整源代码.请注意,它仍在进行中,可能在其他地方存在逻辑错误.
print_hex: ; prints the value stored at bx in hex
pusha ; push all the local registers to the stack
ascii_table: ; define a table to store ascii characters for conversion
db "0123456789ABCDEF"
mov ah, 0x0e ; move 0x0e to the high byte of ax in preparation for a teletype interrupt …Run Code Online (Sandbox Code Playgroud) 我在 RTD 上记录了一个 python 模块:http : //modernglextexttools.readthedocs.io
这是另一个模块的扩展,我想在两者之间建立联系。我希望参数和返回类型作为链接工作。这是一个例子。
我的conf.py
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.githubpages',
'sphinx.ext.intersphinx', # added this but does not help
'sphinxcontrib.napoleon'
]
Run Code Online (Sandbox Code Playgroud)
以下是链接外部类的方法示例。外部类是ModernGL.Context. 我不确定是否必须配置此类的记录位置。但它应该指向这个链接。
def load(filename, convert=None, ctx=None) -> ModernGL.Texture:
'''
Load a texture. If ctx is ``None`` the default_context is used.
Args:
filename (str): The name of the file to load.
Keyword Args:
convert (str): Convert the texture before loading. Possible values are: ('L', 'RGB', 'RGBA')
ctx …Run Code Online (Sandbox Code Playgroud) 我在python中需要一个过剩的窗口.我使用Python 3.5和PyOpenGL.GLUT有以下异常
Traceback (most recent call last):
File "D:\...\Test.py", line 47, in <module>
if __name__ == '__main__': main()
File "D:\...\Test.py", line 9, in main
glutInit(sys.argv)
File "C:\...\OpenGL\GLUT\special.py", line 333, in glutInit
_base_glutInit( ctypes.byref(count), holder )
File "C:\...\OpenGL\platform\baseplatform.py", line 407, in __call__
self.__name__, self.__name__,
OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit,
check for bool(glutInit) before calling
Run Code Online (Sandbox Code Playgroud)
平台:Windows
为什么我会收到此错误?
这是我的代码:
from OpenGL.GLUT import *
import sys
glutInit(sys.argv)
Run Code Online (Sandbox Code Playgroud) 我正在使用Pillow 9.1.0将图像上下翻转。
from PIL import Image
img = Image.open('example.png')
flipped = img.transpose(Image.FLIP_TOP_BOTTOM)
Run Code Online (Sandbox Code Playgroud)
最近出现一个警告:
DeprecationWarning: FLIP_TOP_BOTTOM is deprecated and will be removed in Pillow 10 (2023-07-01). Use Transpose.FLIP_TOP_BOTTOM instead.
flipped = img.transpose(Image.FLIP_TOP_BOTTOM)
Run Code Online (Sandbox Code Playgroud)
我尝试从 PIL 导入 Transpose 但没有成功。
DeprecationWarning: FLIP_TOP_BOTTOM is deprecated and will be removed in Pillow 10 (2023-07-01). Use Transpose.FLIP_TOP_BOTTOM instead.
flipped = img.transpose(Image.FLIP_TOP_BOTTOM)
Run Code Online (Sandbox Code Playgroud)
Traceback (most recent call last):
File "example.py", line 1, in <module>
from PIL import Image, Transpose
ImportError: cannot import name 'Transpose' from 'PIL' (.../site-packages/PIL/__init__.py) …Run Code Online (Sandbox Code Playgroud) 截至今天,如果我要求publish_stream许可,我可以保留此访问令牌并继续永久使用它吗?(或者我必须每隔xxx天更新一次)?
如果我只是使用,我会好吗publish_stream?
另外,我从回复中得到了回复:
access_token=AAAEpyvU...8KktpSub&expires=3673
Run Code Online (Sandbox Code Playgroud)
"expires"意思?剩下3673秒?我有一个PublishSubject注册doOnSubscribe和doOnUnsubscribe操作.如果订阅完成,则不会调用这两个操作.
private PublishSubject<Long> publishSubject;
private Subscription subscription;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
publishSubject = PublishSubject.create();
publishSubject.doOnSubscribe(new Action0() {
@Override
public void call() {
Log.d("SUBJECT", "Someone subscribed.");
}
});
publishSubject.doOnUnsubscribe(new Action0() {
@Override
public void call() {
Log.d("SUBJECT", "Someone UNsubscribed.");
}
});
Observable.interval(1, TimeUnit.SECONDS).subscribe(new Action1<Long>() {
@Override
public void call(final Long tick) {
publishSubject.onNext(tick);
}
});
}
@Override
protected void onResume() {
super.onResume();
subscription = publishSubject.subscribe(new Action1<Long>() {
@Override
public void call(final Long aLong) …Run Code Online (Sandbox Code Playgroud) 这是一个简短的例子。
from PIL import ImageFont, ImageDraw
draw = ImageDraw.Draw(image)
# use a bitmap font
font = ImageFont.load("arial.pil")
draw.text((10, 10), "hello", font=font)
# use a truetype font
font = ImageFont.truetype("arial.ttf", 15)
draw.text((10, 25), "world", font=font)
Run Code Online (Sandbox Code Playgroud)
我想知道字体是否缺少渲染文本中的任何字形。
当我尝试渲染丢失的字形时,我得到一个空方块。
draw.text((10, 10), chr(1234), font=font)
Run Code Online (Sandbox Code Playgroud)
这两个问题几乎是一样的。
我更喜欢使用 Pillow 来确定我想要什么。PyPI 的其他模块也受到欢迎。
这是我的代码:
import asyncio, socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('', 1234))
sock.setblocking(False)
queue = asyncio.Queue()
def sock_reader():
print(sock.recv(1024))
# x = yield from queue
def test_sock_reader():
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(b'HELLO', ('127.0.0.1', 1234))
loop = asyncio.get_event_loop()
loop.add_reader(sock, sock_reader)
loop.call_later(0.5, test_sock_reader)
loop.run_forever()
loop.close()
Run Code Online (Sandbox Code Playgroud)
这是输出:
b'HELLO'
Run Code Online (Sandbox Code Playgroud)
# x = yield from queue取消注释该行时,程序不再打印b'Hello'.
为什么yield from影响应该已经执行的命令?
如何使用 python3 Pillow 清除区域ImageDraw?
im = Image.new('RGBA', (1200, 400), (0, 0, 0, 0))
draw = ImageDraw.Draw(im)
...
draw.rectangle((100, 100, 300, 150), fill=(0, 0, 0, 0))
draw.text((100, 100), 'Hello World!', font=font, fill=(0, 0, 255, 255))
canvas.write(im.tobytes())
Run Code Online (Sandbox Code Playgroud)
我的想法是绘制一个矩形,但由于组件为 ,fill=(0, 0, 0, 0)因此该矩形会混合到图像中而不会改变任何像素。alpha0
我每秒更新图像 60 次,但我无法重绘整个图像。
我创建了一个模块ModernGL来简化在python3中使用OpenGL的过程.
这就是我为具有1,2,3或4个组件的渲染缓冲区选择正确格式的方法:
const int int_formats[] = {0, GL_R8, GL_RG8, GL_RGB8, GL_RGBA8};
const int float_formats[] = {0, GL_R32F, GL_RG32F, GL_RGB32F, GL_RGBA32F};
int format = floats ? float_formats[components] : int_formats[components];
...
gl.RenderbufferStorage(GL_RENDERBUFFER, format, width, height);
Run Code Online (Sandbox Code Playgroud)
例如,使用components=1和floats=False将选择的渲染缓冲区format=GL_R8
Previusly(在此提交之前)我有:
const int int_formats[] = {0, GL_R8UI, GL_RG8UI, GL_RGB8UI, GL_RGBA8UI};
Run Code Online (Sandbox Code Playgroud)
根据此文档:如果您需要3组件无符号整数格式,每个组件8位,则使用GL_RGB8UI.GL_R16F是一个单组件浮点格式,每个组件使用16位.
然而
当我选择GL_R8UIglReadPixels()将失败GL_INVALID_OPERATION
时我选择GL_R8glReadPixels()将读取像素为unsigned chars
我有一个测试失败了非支持格式.
GL_R8和之间有什么区别GL_R8UIGL_R8UI,但读取失败.注意:我测试过GL_R8UI,GL_RGB8UI …
python ×7
python-3.x ×4
android ×1
assembly ×1
c++ ×1
deprecated ×1
facebook ×1
glut ×1
nasm ×1
opengl ×1
pyopengl ×1
python-3.5 ×1
rx-android ×1
rx-java ×1
tensorflow ×1
x86 ×1