Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

During handling of the above exception, another exception occurred #265

Closed
Nakasu-ksm opened this issue May 22, 2019 · 18 comments
Closed

During handling of the above exception, another exception occurred #265

Nakasu-ksm opened this issue May 22, 2019 · 18 comments

Comments

@Nakasu-ksm
Copy link

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "train.py", line 6, in
import tensorflow as tf
File "C:\Users\admin\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_init_.py", line 24, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Users\admin\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python_init_.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "C:\Users\admin\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\admin\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\admin\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\admin\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\admin\AppData\Local\Programs\Python\Python37\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\admin\AppData\Local\Programs\Python\Python37\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: 找不到指定的模块。

Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.

@Nakasu-ksm
Copy link
Author

@JiahuiYu

@Nakasu-ksm Nakasu-ksm changed the title now have this During handling of the above exception, another exception occurred May 22, 2019
@JiahuiYu
Copy link
Owner

I have no idea how to execute on Windows. Apparently it relates to the python environment: python and tensorflow.

@Nakasu-ksm
Copy link
Author

what can i do

@Nakasu-ksm
Copy link
Author

cuda or cudnn

@Nakasu-ksm
Copy link
Author

i use the gpu vesion

@JiahuiYu
Copy link
Owner

I would suggest you search how to execute tensorflow on Windows with GPU.

@Nakasu-ksm
Copy link
Author

thanks i solve this question but train.py Get stuck �[32m[2019-05-22 23:29:51 @weights_viewer.py:60]�[0m Total size of trainable weights: 0G 10M 184K 136B (Assuming32-bit data type.)

@Nakasu-ksm
Copy link
Author

Traceback (most recent call last):
File "test.py", line 23, in
ng.get_gpus(1)
File "C:\Users\admin\AppData\Local\Programs\Python\Python37\lib\site-packages\neuralgym\utils\gpus.py", line 54, in get_gpus
gpu_id = int(s[0])
IndexError: list index out of range

the test.py how can i modify it

import argparse

import cv2
import numpy as np
import tensorflow as tf
import neuralgym as ng

from inpaint_model import InpaintCAModel

parser = argparse.ArgumentParser()
parser.add_argument('--image', default='', type=str,
help='The filename of image to be completed.')
parser.add_argument('--mask', default='', type=str,
help='The filename of mask, value 255 indicates mask.')
parser.add_argument('--output', default='output.png', type=str,
help='Where to write output.')
parser.add_argument('--checkpoint_dir', default='', type=str,
help='The directory of tensorflow checkpoint.')

if name == "main":
ng.get_gpus(1)
args = parser.parse_args()

model = InpaintCAModel()
image = cv2.imread(args.image)
mask = cv2.imread(args.mask)

assert image.shape == mask.shape

h, w, _ = image.shape
grid = 8
image = image[:h//grid*grid, :w//grid*grid, :]
mask = mask[:h//grid*grid, :w//grid*grid, :]
print('Shape of image: {}'.format(image.shape))

image = np.expand_dims(image, 0)
mask = np.expand_dims(mask, 0)
input_image = np.concatenate([image, mask], axis=2)

sess_config = tf.ConfigProto()
sess_config.gpu_options.allow_growth = True
with tf.Session(config=sess_config) as sess:
    input_image = tf.constant(input_image, dtype=tf.float32)
    output = model.build_server_graph(input_image)
    output = (output + 1.) * 127.5
    output = tf.reverse(output, [-1])
    output = tf.saturate_cast(output, tf.uint8)
    # load pretrained model
    vars_list = tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES)
    assign_ops = []
    for var in vars_list:
        vname = var.name
        from_name = vname
        var_value = tf.contrib.framework.load_variable(args.checkpoint_dir, from_name)
        assign_ops.append(tf.assign(var, var_value))
    sess.run(assign_ops)
    print('Model loaded.')
    result = sess.run(output)
    cv2.imwrite(args.output, result[0][:, :, ::-1])

@JiahuiYu
Copy link
Owner

Remove the line of ng.get_gpus(1)

@Nakasu-ksm
Copy link
Author

Traceback (most recent call last):
File "test.py", line 29, in
assert image.shape == mask.shape
AttributeError: 'NoneType' object has no attribute 'shape'

@Nakasu-ksm
Copy link
Author

I don't know why Windows has so many problems

@JiahuiYu
Copy link
Owner

These are very basic errors and I believe you can solve by yourself.

@Nakasu-ksm
Copy link
Author

But I have no idea to solve this

@Nakasu-ksm
Copy link
Author

I will try to solve

@Nakasu-ksm
Copy link
Author

import argparse

import cv2
import numpy as np
import tensorflow as tf
import neuralgym as ng

from inpaint_model import InpaintCAModel

parser = argparse.ArgumentParser()
parser.add_argument('--image', default='', type=str,
help='The filename of image to be completed.')
parser.add_argument('--mask', default='', type=str,
help='The filename of mask, value 255 indicates mask.')
parser.add_argument('--output', default='output.png', type=str,
help='Where to write output.')
parser.add_argument('--checkpoint_dir', default='', type=str,
help='The directory of tensorflow checkpoint.')

if name == "main":

args = parser.parse_args()

model = InpaintCAModel()
image = cv2.imread(args.image)
mask = cv2.imread("C:\Users\admin\Desktop\generative_inpainting-master\examples\mask.png")

assert image.shape == mask.shape

h, w, _ = image.shape
grid = 8
image = image[:h//grid*grid, :w//grid*grid, :]
mask = mask[:h//grid*grid, :w//grid*grid, :]
print('Shape of image: {}'.format(image.shape))

image = np.expand_dims(image, 0)
mask = np.expand_dims(mask, 0)
input_image = np.concatenate([image, mask], axis=2)

sess_config = tf.ConfigProto()
sess_config.gpu_options.allow_growth = True
with tf.Session(config=sess_config) as sess:
    input_image = tf.constant(input_image, dtype=tf.float32)
    output = model.build_server_graph(input_image)
    output = (output + 1.) * 127.5
    output = tf.reverse(output, [-1])
    output = tf.saturate_cast(output, tf.uint8)
    # load pretrained model
    vars_list = tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES)
    assign_ops = []
    for var in vars_list:
        vname = var.name
        from_name = vname
        var_value = tf.contrib.framework.load_variable(args.checkpoint_dir, from_name)
        assign_ops.append(tf.assign(var, var_value))
    sess.run(assign_ops)
    print('Model loaded.')
    result = sess.run(output)
    cv2.imwrite(args.output, result[0][:, :, ::-1])

@Nakasu-ksm
Copy link
Author

but run error

@Nakasu-ksm
Copy link
Author

can you help me

@Nakasu-ksm
Copy link
Author

@JiahuiYu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants