问题列表 - 第279857页

了解 keras Conv2DTranspose 的输出形状

我很难理解 keras.layers.Conv2DTranspose 的输出形状

这是原型:

keras.layers.Conv2DTranspose(
    filters,
    kernel_size,
    strides=(1, 1),
    padding='valid',
    output_padding=None,
    data_format=None,
    dilation_rate=(1, 1),
    activation=None,
    use_bias=True,
    kernel_initializer='glorot_uniform',
    bias_initializer='zeros',
    kernel_regularizer=None,
    bias_regularizer=None,
    activity_regularizer=None,
    kernel_constraint=None,
    bias_constraint=None
)
Run Code Online (Sandbox Code Playgroud)

在文档(https://keras.io/layers/convolutional/)中,我读到:

If output_padding is set to None (default), the output shape is inferred.
Run Code Online (Sandbox Code Playgroud)

在代码(https://github.com/keras-team/keras/blob/master/keras/layers/convolutional.py)中,我读到:

out_height = conv_utils.deconv_length(height,
                                      stride_h, kernel_h,
                                      self.padding,
                                      out_pad_h,
                                      self.dilation_rate[0])
out_width = conv_utils.deconv_length(width,
                                     stride_w, kernel_w,
                                     self.padding,
                                     out_pad_w,
                                     self.dilation_rate[1])
if self.data_format == 'channels_first':
    output_shape = (batch_size, self.filters, out_height, out_width)
else:
    output_shape = (batch_size, out_height, out_width, self.filters)
Run Code Online (Sandbox Code Playgroud)

和(https://github.com/keras-team/keras/blob/master/keras/utils/conv_utils.py):

def deconv_length(dim_size, …
Run Code Online (Sandbox Code Playgroud)

layer shapes keras

7
推荐指数
1
解决办法
8455
查看次数

Android 启动画面切换

我有一个呈现可绘制对象的 Android 启动画面。当它通过冷启动打开时,我发现我的资产只是向上移动。

你可以在下面找到合适的代码,所有不必要的代码都被省略了。

这是轻微的变化:

在此处输入图片说明

SplashActivity.java

public class SplashActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }
}
Run Code Online (Sandbox Code Playgroud)

主活动.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    SplashScreen.show(this, R.style.SplashTheme);
    super.onCreate(savedInstanceState);
}
Run Code Online (Sandbox Code Playgroud)

res/drawable/background_splash.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
    <item android:drawable="@color/splash_background_color"/>
    <item
        android:gravity="center"
        >
        <bitmap
            android:src="@drawable/x150"/>
    </item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

res/layout/launch_screen.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/splash_background_color">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:src="@drawable/background_splash"
        />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

res/values/styles.xml

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> …
Run Code Online (Sandbox Code Playgroud)

android react-native

10
推荐指数
1
解决办法
1199
查看次数

隐藏JSON中的属性

我有一个包含2个玩家的结构表,但是Player当我发送JSON时,我需要忽略结构中的一些属性.

我可以使用json:"-",但随后属性将被忽略,我只需要在发送Table结构时忽略它.当我发送Player代码的其他部分时,我需要这些属性.

我有:

type Player struct {
    Id            Int64   `json:"id"`
    Username      string  `json:"username,omitempty"`
    Password      string          `json:"-,omitempty"`
    Email         string          `json:"email,omitempty"`
    Birthdate     time.Time       `json:"birthdate,omitempty"`
    Avatar        string  `json:avatar,omitempty"`
}

type Table struct {
    Id           int       `json:"id"`
    PlayerTop    Player      `json:"playerTop"`
    PlayerBottom Player      `json:"playerBottom"`
}
Run Code Online (Sandbox Code Playgroud)

我需要:

{
    "Table": {
        "id": 1,
        "playerBottom": {
            "id": 1,
            "username": "peter",
            "avatar": "avatar.png"
        },
        "playerTop": {
            "id": 1,
            "username": "peter",
            "avatar": "avatar.png"
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

玩家来自数据库,因此属性不为空.

a)我可以这样做:

myTable = new(Table)

myTable.PlayerBottom.Email = "" …
Run Code Online (Sandbox Code Playgroud)

json go

5
推荐指数
1
解决办法
87
查看次数

将 Django 模型迁移到 Postgresql 架构

我想通过 Django 迁移在特定的 Postgresql 架构(即“schema1”)中创建一个新表。

尽管遵循此博客此帖子中的方法 1 ,迁移仍将表发送到默认架构“public”而不是“schema1”。

在 中settings.py,我有:

DATABASES = {

    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'OPTIONS': {
                        'options': '-c search_path=django,public'
                    },
        'NAME': 'myDB',
        'USER': 'username',
        'PASSWORD': '***',
        'HOST': 'my.host.address',
        'PORT': '1234',
    },

    'schema1': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'OPTIONS': {
                    'options': '-c search_path=schema1,public'
                },
    'NAME': 'myDB',
    'USER': 'username',
    'PASSWORD': '***',
    'HOST': 'my.host.address',
    'PORT': '1234',
    } 
}  


#Path to DBrouter to handle PG schemas /sf/answers/3570520901/
DATABASE_ROUTERS = ('djangogirls.dbrouters.MyDBRouter',)
Run Code Online (Sandbox Code Playgroud)

在 中djangogirls/dbrouters.py,我有:

from legacydbapp.models import …
Run Code Online (Sandbox Code Playgroud)

django postgresql database-schema

5
推荐指数
1
解决办法
9802
查看次数

Git 预提交钩子配置

我正在按照办公室指南创建钩子并将其添加到预提交检查过程中。我需要创建 3 个文件

  .pre-commit-config.yaml

  .pre-commit-hooks.yaml

   theCheckFile.sh
Run Code Online (Sandbox Code Playgroud)

配置文件配置hooks文件该文件调用theCheckFils.sh文件来检查我的代码风格。

Q.1我应该把这些文件放在哪里?我目前将它们放入我的项目文件夹中,并编辑 .gitignore 文件以忽略所有它们,有更好的建议吗?或者这样就可以了。

Q.2 pre-commit-config.yaml 文件中需要 rev,我应该在哪里找到此信息,我当前使用的代码 Repo 中没有版本信息,我可以随机创建一个数字吗?

git pre-commit-hook pre-commit.com

3
推荐指数
1
解决办法
1万
查看次数

检查打字稿中通用参数的类型

我正在使用打字稿在反应应用程序中工作。其中一个函数在其中一个变量中接收泛型类型。

如何检查变量的类型 T?这可能吗?

MyFunction<T>(newValues: Array<T>) {
    if (typeof T === "string") {
        // do some stuff
    }
}
Run Code Online (Sandbox Code Playgroud)

typescript

13
推荐指数
1
解决办法
1万
查看次数

BytesIO -&gt; BufferedIOBase -&gt; TextIOWrapper 无法读取行

我正在尝试从像对象这样的字节中读取行。

这是一个非常简单的例子。我知道它可以以不同的方式完成,但保持这种流动很重要(BytesIO -> BufferedIOBase -> TextIOWrapper)。

import io
bytes_io = io.BytesIO(b"a\nb\nc")
buffered_io_base = io.BufferedIOBase(bytes_io)
text_io = io.TextIOWrapper(buffered_io_base)
for line in text_io:
    print(line)
Run Code Online (Sandbox Code Playgroud)

这最终会出现错误:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
io.UnsupportedOperation: not readable
Run Code Online (Sandbox Code Playgroud)

Python 版本 3.6.5

python io python-3.x

0
推荐指数
1
解决办法
1635
查看次数

不允许操作mkdir \ path \\ node_modules \\ @ types \''

我正在尝试运行命令,npm install --no-bin-links作为尝试解决其他问题的一部分。最初的问题来自我尝试安装aldeed:simple-schema软件包,这导致有关缺少simpl-schema(无e)依赖项的错误。我开始跑步npm install --save simpl-schema

我的项目然后崩溃,并给出一个错误:

Error: EPERM: operation not permitted, mkdir 'D:\Code\DB-MM- Test\node_modules\@types'
npm ERR!  { [Error: EPERM: operation not permitted, mkdir 'D:\Code\DB-MM-Test\node_modules\@types']
npm ERR!   cause:
npm ERR!    { Error: EPERM: operation not permitted, mkdir 'D:\Code\DB-MM-Test\node_modules\@types'
npm ERR!      errno: -4048,
npm ERR!      code: 'EPERM',
npm ERR!      syscall: 'mkdir',
npm ERR!      path: 'D:\\Code\\DB-MM-Test\\node_modules\\@types' },
npm ERR!   stack:
npm ERR!    'Error: EPERM: operation not permitted, mkdir \'D:\\Code\\DB-MM-Test\\node_modules\\@types\'',
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR! …
Run Code Online (Sandbox Code Playgroud)

npm meteor meteor-packages

4
推荐指数
1
解决办法
798
查看次数

弹性4J + Spring Boot 2.x

我在reative API spring boot应用程序中使用resilience4j进行容错。我可以看到,即使 Mono 返回错误,所有事件都被视为成功。

服务层

    @Override
    @CircuitBreaker(name = "member-service")
    public Mono<String> getMemberInfo(String memberId) {
        return wsClient.getMemberInfo(memberId); 
       // This call will return WSException whenever there is 4XX or 5XX error
    }
Run Code Online (Sandbox Code Playgroud)

application.yml配置

resilience4j.circuitbreaker:
  backends:
    member-service:
      ringBufferSizeInClosedState: 1
      ringBufferSizeInHalfOpenState: 2
      waitInterval: 10000
      failureRateThreshold: 75
      registerHealthIndicator: true
      recordExceptions:
        - com.xx.WSException
      ignoreExceptions:
        - com.xxx.WSClientException
Run Code Online (Sandbox Code Playgroud)

我故意更改了 URI 路径,以便 WebClient 始终返回 404 错误,从而引发 WSException。当我看到下面的端点时,类型总是成功。我错过了什么?

http://localhost:8088/circuitbreaker-events/member-service

{
"circuitBreakerEvents": [
{
"circuitBreakerName": "member-service",
"type": "SUCCESS",
"creationTime": "2019-02-18T21:56:21.588+05:30[Asia/Calcutta]",
"durationInMs": 6
},
{
"circuitBreakerName": "member-service",
"type": "SUCCESS", …
Run Code Online (Sandbox Code Playgroud)

circuit-breaker project-reactor spring-webflux resilience4j

1
推荐指数
1
解决办法
4636
查看次数

如何静默地对抛出的错误进行 Jest 测试

我正在编写一个测试来断言如果提供一个道具而不是另一个道具,组件会抛出错误。

测试本身通过了,但控制台仍然抱怨未捕获的错误并打印整个堆栈跟踪。有什么办法可以让 Jest 停止打印这些信息,因为它会污染测试运行器并使它看起来像是失败了。

作为参考,这是我的测试:

it("throws an error if showCancel is set to true, but no onCancel method is provided", () => {
    // Assert that an error is thrown
    expect(() => mount(<DropTarget showCancel={ true }/>)).toThrowError("If `showCancel` is true, you must provide an `onCancel` method");
});
Run Code Online (Sandbox Code Playgroud)

错误本身在这里抛出:

if(props.showCancel && !props.onCancel) {
    throw new Error("If `showCancel` is true, you must provide an `onCancel` method");
}
Run Code Online (Sandbox Code Playgroud)

testing unit-testing typescript reactjs jestjs

6
推荐指数
1
解决办法
2090
查看次数