小编Vik*_*tam的帖子

当启用急切执行时,传递给 Optimizer.compute_gradients 的 `loss` 应该是一个函数

我是 TensorFlow 的新手,我刚刚开始学习和理解它。我正在neural style transfer解决问题,我正在使用 tensorflow version 1.14

我收到一个错误损失传递给 Optimizer.compute_gradients should be a function when Eage Execution is enabled

我试图通过使用 TensorFlow 图而不是 来解决这个问题eager execution,但它不起作用。我想使用,eager execution因为它看起来更像是 Pythonic 的方式。

这是我的代码,很抱歉将整个代码放在这里,请在我的代码中提出更正建议。

import scipy
import tensorflow as tf
import tensorflow.contrib.eager as tfe
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
from scipy import misc
from skimage.transform import resize
from tensorflow.keras.applications.vgg19 import VGG19, preprocess_input
from tensorflow.keras import backend as K

tf.enable_eager_execution()
print('Eager …
Run Code Online (Sandbox Code Playgroud)

python tensorflow

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

从zip文件中的csv创建Dataframe

我试图在pandas数据帧中读取WGIData.csv文件.WGIData.csv存在于我从此网址下载的zip文件中

http://databank.worldbank.org/data/download/WGI_csv.zip

但是当我试图阅读时,它会抛出错误BadZipFile:文件不是zip文件

这是我的python代码

import pandas as pd
from urllib.request import urlopen
from zipfile import ZipFile

class Get_Data():

    def Return_csv_from_zip(self, url):
        self.zip = urlopen(url)
        self.myzip = ZipFile(self.zip)
        self.myzip = self.zip.extractall(self.myzip)
        self.file = pd.read_csv(self.myzip)
        self.zip.close()

        return self.file

url = 'http://databank.worldbank.org/data/download/WGI_csv.zip'
data = Get_Data()
df = data.Return_csv_from_zip(url)
Run Code Online (Sandbox Code Playgroud)

python unzip zipfile pandas

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

标签 统计

python ×2

pandas ×1

tensorflow ×1

unzip ×1

zipfile ×1