拟合 Keras 顺序模型给出 ValueError: Failed to conversion a NumPy array to a Tensor (Unsupported object type numpy.ndarray)

2024-02-14

我有以下列表数组(每部电影的演员):

partial_x_train_actors=array([list([b'victor mclaglen', b'jon hall', b'frances farmer', b'olympe bradna', b'gene lockhart', b'douglass dumbrille', b'francis ford', b'ben welden', b'abner biberman', b'pedro de cordoba', b'rudy robles', b'bobby stone', b'nellie duran', b'james flavin', b'nina campana']),
       list([b'jessica biel', b'ben barnes', b'kristin scott thomas', b'colin firth', b'kimberley nixon', b'katherine parkinson', b'kris marshall', b'christian brassington', b'charlotte riley', b'jim mcmanus', b'pip torrens', b'jeremy hooton', b'joanna bacon', b'maggie hickey', b'georgie glen']),
       list([b'gr\xc3\xa9gori derang\xc3\xa8re', b'anouk grinberg', b'aur\xc3\xa9lien recoing', b'niels arestrup', b'yann collette', b'laure duthilleul', b'david assaraf', b'pascal demolon', b'jean-baptiste iera', b'richard sammel', b'vincent crouzet', b'fred epaud', b'pascal elso', b'nicolas giraud', b'micha\xc3\xabl abiteboul']),
       ...,
       list([b'jason schwartzman', b'mickey rourke', b'brittany murphy', b'john leguizamo', b'patrick fugit', b'mena suvari', b'chloe hunter', b'elisa bocanegra', b'julia mendoza', b'china chow', b'nicholas gonzalez', b'debbie harry', b'josh peck', b'charlotte ayanna', b'eric roberts']),
       list([b'fred kirschenmann', b'daniel salatin', b'joel salatin', b'paul willis', b'chuck wirtz']),
       list([b'jan sebastian', b'tray loren', b'paul muzzcat', b'brad koepenick', b'jerry armstrong', b'ben sebastian', b'reyn hubbard', b'levita gros', b'betty flemming', b'randolph parro', b'susan serigny', b'keith gros', b'rocky dugas', b'sid larrwiere', b'jocelyn boudreaux'])],
      dtype=object)

由于我想将其用作 Keras 模型的输入,因此我必须将列表数组转换为数组数组。为此,我运行以下代码,取自这个问题 https://stackoverflow.com/questions/57760510/converting-array-of-lists-to-keras-input

partial_x_train_actors_array=[]

for i in range(len(partial_x_train_actors)):
    
    partial_x_train_actors_array.append(np.array(list(x for x in partial_x_train_actors[i])))

partial_x_train_actors_array = np.asarray(partial_x_train_actors_array)=
type(partial_x_train_actors_array[0])

所以现在我明白了:

array([array([b'victor mclaglen', b'jon hall', b'frances farmer',
       b'olympe bradna', b'gene lockhart', b'douglass dumbrille',
       b'francis ford', b'ben welden', b'abner biberman',
       b'pedro de cordoba', b'rudy robles', b'bobby stone',
       b'nellie duran', b'james flavin', b'nina campana'], dtype='|S18'),
       array([b'jessica biel', b'ben barnes', b'kristin scott thomas',
       b'colin firth', b'kimberley nixon', b'katherine parkinson',
       b'kris marshall', b'christian brassington', b'charlotte riley',
       b'jim mcmanus', b'pip torrens', b'jeremy hooton', b'joanna bacon',
       b'maggie hickey', b'georgie glen'], dtype='|S21'),
       array([b'gr\xc3\xa9gori derang\xc3\xa8re', b'anouk grinberg',
       b'aur\xc3\xa9lien recoing', b'niels arestrup', b'yann collette',
       b'laure duthilleul', b'david assaraf', b'pascal demolon',
       b'jean-baptiste iera', b'richard sammel', b'vincent crouzet',
       b'fred epaud', b'pascal elso', b'nicolas giraud',
       b'micha\xc3\xabl abiteboul'], dtype='|S19'),
       ...,
       array([b'jason schwartzman', b'mickey rourke', b'brittany murphy',
       b'john leguizamo', b'patrick fugit', b'mena suvari',
       b'chloe hunter', b'elisa bocanegra', b'julia mendoza',
       b'china chow', b'nicholas gonzalez', b'debbie harry', b'josh peck',
       b'charlotte ayanna', b'eric roberts'], dtype='|S17'),
       array([b'fred kirschenmann', b'daniel salatin', b'joel salatin',
       b'paul willis', b'chuck wirtz'], dtype='|S17'),
       array([b'jan sebastian', b'tray loren', b'paul muzzcat',
       b'brad koepenick', b'jerry armstrong', b'ben sebastian',
       b'reyn hubbard', b'levita gros', b'betty flemming',
       b'randolph parro', b'susan serigny', b'keith gros', b'rocky dugas',
       b'sid larrwiere', b'jocelyn boudreaux'], dtype='|S17')],
      dtype=object)

但这都不足以摆脱输入张量的类型,因为我收到此错误:

ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray).

我的模型拟合过程

# import the pre-trained model
model = "https://tfhub.dev/google/tf2-preview/gnews-swivel-20dim/1"
hub_layer = hub.KerasLayer(model, output_shape=[20], input_shape=[], dtype=tf.string, trainable=True)

# create the neural network structure
model = tf.keras.Sequential(name="English_Google_News_130GB_witout_OOV_tokens")
model.add(hub_layer)
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(i, kernel_regularizer=regularizers.l2(neural_network_parameters['l2_regularization']),
                                        activation=neural_network_parameters['dense_activation']))
model.add(tf.keras.layers.Dropout(neural_network_parameters['dropout_rate']))
model.add(tf.keras.layers.Dense(y_val.shape[1], 

activation=neural_network_parameters['output_activation']))
        
#model.name("English Google News 130GB witout OOV tokens")
print(model.summary())
        
#instantiate Optimizer
optimizer = optimizer_adam_v2(len(partial_x_train_actors_array), validation_split_ratio, i)

model.compile(optimizer=optimizer,
              loss=neural_network_parameters['model_loss'],
              metrics=[neural_network_parameters['model_metric']])

plot_model(model, to_file=os.path.join(os.getcwd(), 'model_three\\network_structure_english_google_news_without_OOV_model_{0}.png'.format(version_data_control)))

history = model.fit([partial_x_train_features, partial_x_train_plot, partial_x_train_actors_array, partial_x_train_reviews],
                        partial_y_train,
                        steps_per_epoch=int(np.ceil((len(partial_x_train_actors_array)*0.8)//16)),
                        epochs=100,
                        batch_size=16,
                        validation_split=0.2
                        verbose=0,
                        callbacks=callback("english_google_news_without_oovtokens", model))

[编辑] - 04.07.2020

我想补充一点,我已经为另一个实验完成了序列的填充,上面列出的演员列表已转换为下面的列表

partial_x_train_actors=array([[ 2024,  3228,   451, ..., 18119,     0,     0],
       [ 3230,  7889, 12357, ...,     0,     0,     0],
       [20001, 20001, 20001, ...,     0,     0,     0],
       ...,
       [ 6887, 20001, 15352, ..., 20001, 20001, 20001],
       [10206, 20001,  3426, ..., 20001,     0,     0],
       [ 2969,  5903,   447, ...,     0,     0,     0]])

但是,当我在神经网络的 .fit() 中应用此列表时,出现以下错误

ValueError: Error when checking input: expected keras_layer_4_input to have 1 dimensions, but got array with shape (39192, 17)

(39192, 17) 是 actor 数组的形状

[编辑 2] - 2020 年 7 月 5 日

Trial 1(失败的)

根据提供的答案的一些建议,我尝试更改 hub.Keraslayer 的输入形状:

hub_layer = hub.KerasLayer(model, output_shape=[20], input_shape=[len(y_train)], dtype=tf.string, trainable=True)

我让它等于我的训练输入长度#39192 每个演员、情节、功能、评论的数据。

Error produced: enter image description here From the error, I can guess that the input_shape should be []?

Trial 2(失败的)

#list of actors (training data) tensors
actors_training_tensors=np.array([tf.convert_to_tensor(partial_x_train_actors[i]) for i in range(len(partial_x_train_actors))])
actors_testing_tensors=np.array([tf.convert_to_tensor(x_val_actors[i]) for i in range(len(x_val_actors))])

又报错:

ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type tensorflow.python.framework.ops.EagerTensor).

我将演员的输入列表转换为张量。请注意,只有演员的列表有问题,因为它们作为名称存储在列表 [[name1, name2, name3]] 中。我对情节、特征或评论输入都没有问题,因为它们被保存为语料库列表。

Trial 3(失败的)

根据评论,我同样使用了数据 API:

data_tf=tf.data.Dataset.from_tensor_slices([partial_x_train_features, partial_x_train_plot, partial_x_train_actors_array, partial_x_train_reviews])

我又收到一个错误:

ValueError: Can't convert Python sequence with mixed types to Tensor.

所以我搜索了一下,我发现了这个question https://stackoverflow.com/questions/49824872/convert-python-sequence-with-multiple-datatypes-to-tensor文档 https://www.tensorflow.org/guide/tensor#data_types, 我做了以下更改(添加了 tf.constant):

data_tf=tf.data.Dataset.from_tensor_slices([tf.constant(partial_x_train_features), tf.constant(partial_x_train_plot), tf.constant(partial_x_train_actors_array), tf.constant(partial_x_train_reviews)])

此外,我似乎无法将 NumPy 字符串数组转换为浮点数张量。也许这就是序列填充发挥重要作用的地方。但是,如果您遵循这个链接 https://www.tensorflow.org/hub/tutorials/tf2_text_classification在我从中得到这个想法的张量流文章中,您会注意到用户仅提供字节字符串而不是填充序列作为输入。

请注意,解决所有这些问题的方法就是使用“”.join() 命令来展平参与者列表。然而,演员只是名字的文本,而不是单独的名字。尽管它有效,但我认为为了获得更好的结果,应该为演员提供单独的名称,因为神经网络无法自行区分名称。

[输入数据进行调试 - 问题复制]

如果有人想要复制和调试问题,下面我代表我的 4 个输入层(数据样本)和来自 Tensorflow 的文章 https://www.tensorflow.org/hub/tutorials/tf2_text_classification我已经遵循了。

这是问题的GitHub 链接 https://github.com/tensorflow/tensorflow/issues/41109发布了问题。当我在本地运行代码时,除了附加的 GitHub 问题中出现的 EarlyStopping 错误之外,一切看起来都很好。我将重新检查我使用的数据,因为 GitHub 链接中提供的数据是要使用的正确数据。


当您尝试转换时,您收到此错误numpy.ndarry到张量。 简而言之,您的数组的长度不同,在将其转换为张量时不被接受。

你要做的就是让你的x的长度相同并且y的长度相同。

有多种方法可以实现这一目标。根据您提供的代码,您可以使用如下所示的代码: 下面的代码是伪代码,它只是为了演示您需要相等长度的数组。

for i in range(len(partial_x_train_actors)):
    
    partial_x_train_actors_array.append(np.array(list(x for x in partial_x_train_actors[i:5]))) # for example getting only 5 elements from the list, you can change as per your need

另一种方法是使用tf.dataAPI 使用发电机 https://www.tensorflow.org/api_docs/python/tf/data/Dataset#from_generator将您的数据集转换为tf.data.Dataset然后使用tf.data.Dataset.padded_batch填充批次以使数据集长度相等。这是 APIlink https://www.tensorflow.org/api_docs/python/tf/data/Dataset#padded_batch.

[问题编辑后] 数组形状的第二个问题是由于您已将输入形状编码为 []。

hub_layer = hub.KerasLayer(model, output_shape=[20], input_shape=[], dtype=tf.string, trainable=True)

由于这个原因,您会收到输入层期望 1 维但收到的错误 (39192,17)。正如你在你的model.fit()你用x as

[partial_x_train_features, partial_x_train_plot, partial_x_train_actors_array, partial_x_train_reviews]

我建议您根据您的数据集而不是 [] 更改 input_shape。

如果您仍然遇到任何问题,我会请求发布 Github 链接,以便我可以调试以查看实际问题。

[05/07/2020] - 更新

我已经调试了您的代码,对您的输入数据进行了一些更改,并使其正常工作。我已经用过tf.data.Dataset.from_generator用于连接数据的 API。我已经对您的损失函数和优化器进行了更改,以便我可以进行调试。您可以根据您的需要进行更改。另外,请确保输入partial_x_train_reviews, partial_x_train_plot and partial_x_train_features应该看起来像这样。但如果你想保持旧的方式改变def generator():相应的方法。请让我知道进展如何。我建议,如果您的问题得到解决,下次也请提供一个可以轻松调试的代码,而不需要进行大量更改才能使其正常工作。希望我的回答对您有帮助。

import tensorflow as tf
import tensorflow_hub as hub

# Train variables
partial_x_train_features = [
    [b'south pago pago victor mclaglen jon hall frances farmer olympe bradna gene lockhart douglass dumbrille francis ford ben welden abner biberman pedro cordoba rudy robles bobby stone nellie duran james flavin nina campana alfred e green treasure hunt adventure adventure'],
    [b'easy virtue jessica biel ben barnes kristin scott thomas colin firth kimberley nixon katherine parkinson kris marshall christian brassington charlotte riley jim mcmanus pip torrens jeremy hooton joanna bacon maggie hickey georgie glen stephan elliott young englishman marry glamorous american brings home meet parent arrive like blast future blow entrenched british stuffiness window comedy romance'],
    [b'fragments antonin gregori derangere anouk grinberg aurelien recoing niels arestrup yann collette laure duthilleul david assaraf pascal demolon jean baptiste iera richard sammel vincent crouzet fred epaud pascal elso nicolas giraud michael abiteboul gabriel le bomin psychiatrist probe mind traumatized soldier attempt unlock secret drove gentle deeply disturbed world war veteran edge insanity drama war'],
    [b'milka film taboos milka elokuva tabuista irma huntus leena suomu matti turunen eikka lehtonen esa niemela sirkka metsasaari tauno lehtihalmes ulla tapaninen toivo tuomainen hellin auvinen salmi rauni mollberg small finnish lapland community milka innocent year old girl live mother miss dead father prays god love haymaking employ drama'],
    [b'sleeping car david naughton judie aronson kevin mccarthy jeff conaway dani minnick ernestine mercer john carl buechler gary brockette steve lundquist billy stevenson michael scott bicknell david coburn nicole hansen tiffany million robert ruth douglas curtis jason david naughton move abandon train car resurrect vicious ghost landlady dead husband mister near fatal encounter comedy horror']]

partial_x_train_plot = [[b'treasure hunt adventure'],
                        [b'young englishman marry glamorous american brings home meet parent arrive like blast future blow entrenched british stuffiness window'],
                        [b'psychiatrist probe mind traumatized soldier attempt unlock secret drove gentle deeply disturbed world war veteran edge insanity'],
                        [b'small finnish lapland community milka innocent year old girl live mother miss dead father prays god love haymaking employ'],
                        [b'jason david naughton move abandon train car resurrect vicious ghost landlady dead husband mister near fatal encounter']]

partial_x_train_actors_array = [[b'victor mclaglen', b'jon hall', b'frances farmer',
                                 b'olympe bradna', b'gene lockhart', b'douglass dumbrille',
                                 b'francis ford', b'ben welden', b'abner biberman',
                                 b'pedro de cordoba', b'rudy robles', b'bobby stone',
                                 b'nellie duran', b'james flavin', b'nina campana'],
                                [b'jessica biel', b'ben barnes', b'kristin scott thomas',
                                 b'colin firth', b'kimberley nixon', b'katherine parkinson',
                                 b'kris marshall', b'christian brassington', b'charlotte riley',
                                 b'jim mcmanus', b'pip torrens', b'jeremy hooton', b'joanna bacon',
                                 b'maggie hickey', b'georgie glen'],
                                [b'gregori derangere', b'anouk grinberg', b'aurelien recoing',
                                 b'niels arestrup', b'yann collette', b'laure duthilleul',
                                 b'david assaraf', b'pascal demolon', b'jean-baptiste iera',
                                 b'richard sammel', b'vincent crouzet', b'fred epaud',
                                 b'pascal elso', b'nicolas giraud', b'michael abiteboul'],
                                [b'irma huntus', b'leena suomu', b'matti turunen',
                                 b'eikka lehtonen', b'esa niemela', b'sirkka metsasaari',
                                 b'tauno lehtihalmes', b'ulla tapaninen', b'toivo tuomainen',
                                 b'hellin auvinen-salmi'],
                                [b'david naughton', b'judie aronson', b'kevin mccarthy',
                                 b'jeff conaway', b'dani minnick', b'ernestine mercer',
                                 b'john carl buechler', b'gary brockette', b'steve lundquist',
                                 b'billy stevenson', b'michael scott-bicknell', b'david coburn',
                                 b'nicole hansen', b'tiffany million', b'robert ruth']]

partial_x_train_reviews = [
    [b'edward small take director alfred e green cast crew uncommonly attractive brilliant assemblage south sea majority curiously undersung piece location far stylize date goldwyn hurricane admittedly riddle cliche formula package visual technical excellence scarcely matter scene stop heart chiseled adonis jon hall porcelain idol frances farmer outline profile s steam background volcano romantic closeup level defies comparison edward small film typically string frame individual work art say outdid do workhorse composer edward ward song score year prior work universal stun phantom opera'],
    [b'jessica biel probably best know virtuous good girl preacher kid mary camden heaven get tackle classic noel coward role early play easy virtue american interloper english aristocratic family unsettle family matriarch kristin scott thomas noel coward write upper class twit pretension wit keep come kind adopt way adopt oscar wilde george bernard shaw kid grow poverty way talent entertain upper class take coward heart felt modern progressive generally term social trend whittakers easy virtue kind aristocrat anybody like hang party invite noel entertain amelia earhart aviation jessica biel character auto race young widow detroit area course area motor car auto race fresh win monte carlo win young ben barnes heir whittaker estates lot land debt barnes bring biel home family mortify classless american way sense recognize class distinction thing get rid title nobility aristocrats story scott thomas dominate family try desperately estate husband colin firth serve world war horror do probably horror trench war slaughter fact class distinction tend melt combat biel kind like wife rule whittaker roost scandal past threatens disrupt barnes biel marriage form crux story turn fact end really viewer figure eventually happen second film adaption easy virtue silent film direct young alfred hitchcock easy virtue actually premier america london star great american stage actress jane cowl guess coward figure american heroine best american theatergoer british one version easy virtue direct flawlessly stephen elliot fine use period music noel coward cole porter end credit really mock upper class coward tradition play going gets tough tough going believe elliott try say class especially one right stuff course obligatory fox hunt upper class indulge oscar wilde say unspeakable uneatable chance younger generation expose noel coward worth see'],
    [b'saw night eurocine event movie european country show day european city hear le bomin barely hear derangere la chambre des officiers fortunately surprise discover great talent unknown large audience derangere absolutely astonish play character antonin verset victim post wwi trauma live trouble scene endure month war cast excellent great work cinematography offer really nice shot great landscape stun face edit really subtile bit memory make sense story minute movie show real chill ww archive action flick like sensitive psychologic movie really think absolutely recommend les fragments d antonin let le bomin'],
    [b'rauni mollberg earth sinful song favorite foreign film establish director major talent film festival circuit get amazing followup milka base work novelist timo mukka till worthy major dvd exposure unlike kaurismaki bros follow double handedly create tongue cheek deadpan finnish film style fan world mollberg commit naturalistic approach film overflow nature life lust earthiness find scandi cinema mainly work famous talent swede vilgot sjoman curious yellow fame director film tabu title imply mollberg effort quite effective sidestep fully treat screen theme incest making adult character father figure real blood relate daddy applies usual merely step father gimmick use countless time american movie incest work matti turunen kristus perkele translate christ devil really common law step dad underage milka beautiful offbeat fashion young girl portray shot irma huntus bring screen sexiness bergman harriet andersson decade earlier create international success summer monika sawdust tinsel imagine actress milka role shame do pursue act career afterward completing strong line leena suomu earth mother type confines act narrow emotional range prove solid rock crucial role bookended spectacularly beautiful shot birch wood winter virtually black white visually color presence milka film quickly develop nature theme presence strange click beak bird talisman early scene milka handyman turunen frolicking naked lake emerge oh natural sex play year old milka man result tastefully shoot intimacy imply ejaculation set trouble come religious aspect remote farm community heavily stress especially enjoy motif spiritual guidance cantor malmstrom quality anti stereotypical play eikka lehtonen instead rigid cruel turn care milka illegitimate baby bear strong romance turunen stud continue service mom woman neighborhood present utterly natural viewer position watch ethnographic exercise moralistic tale powerful technique milka frequently speak directly camera viewer forceful monologue bear crisp sound record sound nature include rain constant motif make milka engross experience view film subtitle knowledge finnish lapp recall best silent era classic direction strong convey dramatic content theme way transcend language kudos mollberg talented cinematographer job work remain obscurity ripe rediscovery'],
    [b'wonder horror film write woody allen wannabe come like check imaginatively direct typical enjoyable haunt place premise solid makeup effect good job major flaw dialogue overload cheeky wisecrack witticisms sample want scary shopping ex wife hit mark deliver inappropriate moment hero battle evil ghost']]

partial_y_train = [[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                   [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
                   [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0],
                   [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                   [0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]]  # multilabel classification



# Using generator for creating the dataset.
def generator():
    for i in range(0, len(partial_y_train)):
        # creates x's and y's for the dataset.
        yield b''.join((partial_x_train_features[i] + partial_x_train_plot[i] + partial_x_train_actors_array[i] +
             partial_x_train_reviews[i])), partial_y_train[i]



dataset = tf.data.Dataset.from_generator(generator, (tf.string, tf.int64),
                                         (tf.TensorShape(None), tf.TensorShape([17])))

dataset = dataset.batch(1)

for i, j in dataset.take(5):
    print(i)
    print(j)

# import the pre-trained model
model = "https://tfhub.dev/google/tf2-preview/gnews-swivel-20dim/1"
hub_layer = hub.KerasLayer(model, output_shape=[20], input_shape=[], dtype=tf.string, trainable=True)

# create the neural network structure
model = tf.keras.Sequential(name="English_Google_News_130GB_witout_OOV_tokens")
model.add(hub_layer)
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(20, activation='relu'))
model.add(tf.keras.layers.Dense(17, activation='softmax'))

# model.name("English Google News 130GB witout OOV tokens")
print(model.summary())

model.compile(optimizer='adam',
              loss=tf.keras.losses.CategoricalCrossentropy(from_logits=True),
              metrics=['accuracy'])

history = model.fit(
    dataset,
    epochs=10,
    batch_size=1)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

拟合 Keras 顺序模型给出 ValueError: Failed to conversion a NumPy array to a Tensor (Unsupported object type numpy.ndarray) 的相关文章

随机推荐

  • 什么相当于 C# 中的 Microsoft.VisualBasic.Collection?

    我有一个方法 它需要一个存储过程名称和一个Microsoft VisualBasic Collection http msdn microsoft com en us library microsoft visualbasic collec
  • 在 Laravel 4 中缓存视图输出

    我知道 Blade 已经缓存了所有 Blade 视图的已编译 PHP 但我想更进一步 我正在开发的一个网站被模块化为组件视图 然后在默认控制器中拼凑在一起 每个 小部件 都有自己的视图 很少更改内容 少数频繁更新的除外 因此 我想缓存这些很
  • Jvectormap 在 div 变化时非常小

    我有两个 div 一个是世界地图 另一个是美国地图 当在世界地图上单击美国时 我想隐藏该 div 并将美国地图带入视图 这是可行的 但地图很小 即使缩放按钮的位置表明 div 的大小是它应该的大小 有任何想法吗 如果我从一开始就将两个 di
  • 获取php中两个日期之间的周数

    我想获取给定两个日期的周数 即从 2012 01 01 到 2012 12 31 周数应该恰好落在上面指定的范围内 您可以为此提供建议吗 像这样的东西应该可以正常工作
  • 如何使用 VisualSVN Server 将现有 Visual Studio 解决方案置于源代码管理之下?

    我有一个现有的 Visual Studio 2013 解决方案 我想使用 VisualSVN Server 将其置于源代码控制之下 我安装了 VisualSVN Server 并创建了一个新的空白存储库 他们的入门 https www vi
  • MuPdf 内存不足

    您好 我在项目中使用 MuPdf 库来查看文档 问题是 当您在平板电脑上的 11 英寸 Activity 中打开 3 7 个文档时 我会出现内存溢出 当您加载新文档时 对先前文档的所有引用都会被销毁 但内存中文档的图像不会被删除 对象在 1
  • 如何在软键盘顶部的建议中添加单词

    有什么办法可以在软键盘的建议中添加单词吗 对于特定的 Edittext 字段 我想将名称列表添加到 android 2 0 中软键盘顶部弹出的建议中 有谁知道这是否可能 Here http android git kernel org p
  • 侧边栏增强插件已安装但不起作用

    系统配置 Sublime Text3 内部版本 3065 Ubuntu 14 04 我想在浏览器中添加预览 发现侧边栏增强功能 Be https github com titoBouzout SideBarEnhancements是最好的插
  • SQL Server DATE 作为字符串检索到 pandas 中

    当我将 日期 变量从 SQL Server 拉入 Python Pandas 时 它作为 对象 出现 我已经安装并尝试了多个驱动程序 代码中显示了尝试过的注释驱动程序 每次都有相同的结果 import pandas as pd import
  • 如何将位图纹理的每个像素渲染到 macOS 上屏幕的每个本机物理像素?

    由于现代 macOS 设备默认选择使用缩放后的 HiDPI 分辨率 位图图像在屏幕上会变得模糊 有没有办法将位图逐像素渲染到显示屏的真实本机物理像素 任何 CoreGraphics OpenGL 或 Metal API 都可以在不改变屏幕显
  • 更改位图的色调,同时保留整体亮度

    我正在尝试编写一个函数 让我可以对位图进行红移或蓝移 同时保留图像的整体亮度 基本上 完全红移的位图将具有与原始亮度相同的亮度 但完全呈红色 即所有像素的 G 和 B 值都相等 蓝色着色相同 但 R 和 G 相等 频谱偏移的程度需要在 0
  • 绝对定位和CSS粘性页脚

    这是我的问题 我使用的布局具有粘性页脚 使用 cssstickyfooter com 方法 在我的容器 div 中 我有一个内容 div 其中包含其他四个 div 像这样 div class container div class cont
  • 何时使用.NET BufferedStream 类?

    The MSDN 网站 http msdn microsoft com en us library system io bufferedstream aspx states 缓冲区是内存中的一个字节块 用于缓存数据 从而减少 拨打运营商电话
  • iBeacon 广告 ID 是否唯一?

    我们正在讨论在跨国多个地点使用 iBeaons 进行大规模部署方案 有人提出的问题是 iBeacons 宣传其存在的 ID 是否是唯一的 因为我们的客户希望真正确保应用程序仅响应特定的 iBeacons 而不响应冒充相同 ID 的其他内容
  • 反转字符串中每个单词中的字母

    我有一个包含空格分隔单词的字符串 我想颠倒每个单词中的字母而不颠倒单词的顺序 我想my string成为ym gnirts 这应该有效 words explode string words array map strrev words ec
  • 在大型数据集上改变窗口大小的滚动平均值

    我想计算向量的滚动平均值 其中窗口随着向量中的每个条目而增长 基本上 我想要所有元素的平均值i th i 1 th i 2 th 依此类推 为了使它更清楚 我将提供一个示例和一个适用于较小数据集但不能很好扩展的解决方案 library zo
  • 来自 application.html.erb 的 Rails 渲染实例变量

    我正在关注 Agile Web Development with Rails 4 这本书 我对渲染的部分感到有点困惑 问题的简单版本是 在 application html erb 文件中它说 render cart 这很令人困惑 因为我认
  • Redis 概念:在内存中还是在数据库中?

    基于http redis io topics faq http redis io topics faq Redis 是一个内存中但持久在磁盘上的数据库 那么我可以知道redis将键 值保存在内存中还是磁盘中 或两者 Redis写入值时 同时
  • 影子根 getElementsByClassName

    我正在使用 LitElement 创建自定义 Web 组件 我对此相当陌生 决定尝试制作图像幻灯片 我用了W3Schools 幻灯片作为参考 https www w3schools com howto howto js slideshow
  • 拟合 Keras 顺序模型给出 ValueError: Failed to conversion a NumPy array to a Tensor (Unsupported object type numpy.ndarray)

    我有以下列表数组 每部电影的演员 partial x train actors array list b victor mclaglen b jon hall b frances farmer b olympe bradna b gene