2016-06-05 6 views
0

Azure에서 호스팅 된 Flask 웹 앱을 Dreamspark 구독으로 만들었습니다. Numpy, Scipy, Theano와 같은 라이브러리를 사용합니다.Azure Flask 웹 앱의 내부 서버 오류

간단한 Theano 계산을 사용하여 앱을 배포하면 완벽하게 작동합니다. 그러나 코드를 더 복잡한 Theano 계산으로 변경하면 내부 서버 오류가 발생합니다.

다음은 샘플 코드입니다. 나는 (합에 대한 Theano 기능 같은) 작동 simpleFunction를 호출하지만 complexFunction (이미지 분류 계산과 같은)를 호출 할 때 다음이 내부 서버 오류 만들 때 : 명확성의 이유로

from flask import Flask 
app = Flask(__name__) 
wsgi_app = app.wsgi_app 

from fileContainingTheanoCode import simpleFunction, complexFunction 

@app.route('/') 
def hello(): 
    result = simpleFunction() 
    thisStr = str(result) 
    return """<html> 
        <head> 
         <title>Test website</title> 
        </head> 
        <body> 
         <h1>"""+thisStr+"""</h1> 
        </body> 
       </html>""" 


if __name__ == '__main__': 
    HOST = os.environ.get('SERVER_HOST', 'localhost') 
    try: 
     PORT = int(os.environ.get('SERVER_PORT', '5555')) 
    except ValueError: 
     PORT = 5555 
    app.run(HOST, PORT) 

을 여기에있다

Event: MODULE_SET_RESPONSE_ERROR_STATUS 
ModuleName FastCgiModule 
Notification EXECUTE_REQUEST_HANDLER 
HttpStatus 500 
HttpReason INTERNAL SERVER ERROR 
HttpSubStatus 0 
ErrorCode The operation completed successfully. 
(0x0) 
:

여기
# Import Libraries---------------------------------------------------------- 
import os 
import sys 
import pickle 
import theano 
import numpy as np 
from theano import tensor as T 
from theano.tensor.nnet.conv import conv2d 
from theano.tensor.signal.downsample import max_pool_2d 
from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams 
srng = RandomStreams() 
import load 

testSize = 10 
trainSize = 2 
#--------------------------------------------------------------------------- 

# Constants----------------------------------------------------------------- 
weightsFile = 'mnist.weights' 
#--------------------------------------------------------------------------- 

# Model--------------------------------------------------------------------- 
# Stuff variable into numpy array with theano float datatype 
def floatX(X): 
    return np.asarray(X, dtype=theano.config.floatX) 


# Initialize weights randomly 
def init_weights(shape): 
    return theano.shared(np.asarray(np.random.randn(*shape) * 0.01, dtype=theano.config.floatX),borrow=True) 


# ReLU - rectify linear function with Theano 
def rectify(X): 
    return T.maximum(X, 0.) 


# Softmax operation 
def softmax(X): 
    e_x = T.exp(X - X.max(axis=1).dimshuffle(0, 'x')) 
    return e_x/e_x.sum(axis=1).dimshuffle(0, 'x') 


# Implements random chance of ignoring a neuron output during training 
def dropout(X, p=0.): 
    if p > 0: 
     retain_prob = 1 - p 
     X *= srng.binomial(X.shape, p=retain_prob, dtype=theano.config.floatX) 
     X /= retain_prob 
    return X 


# Gradient Descent with regularization - parameter reduction 
def RMSprop(cost, params, lr=0.001, rho=0.9, epsilon=1e-6): 
    grads = T.grad(cost=cost, wrt=params) 
    updates = [] 
    for p, g in zip(params, grads): 
     acc = theano.shared(p.get_value() * 0.) 
     acc_new = rho * acc + (1 - rho) * g ** 2 
     gradient_scaling = T.sqrt(acc_new + epsilon) 
     g = g/gradient_scaling 
     updates.append((acc, acc_new)) 
     updates.append((p, p - lr * g)) 
    return updates 


# Constructs the model 
def model(X, w1, w2, w3, w4, p_drop_conv, p_drop_hidden): 
    l1a = rectify(conv2d(X, w1, border_mode='full')) 
    l1 = max_pool_2d(l1a, (2, 2),ignore_border=False) 
    l1 = dropout(l1, p_drop_conv) 

    l2a = rectify(conv2d(l1, w2)) 
    l2 = max_pool_2d(l2a, (2, 2),ignore_border=False) 
    l2 = dropout(l2, p_drop_conv) 

    l3a = rectify(conv2d(l2, w3)) 
    l3b = max_pool_2d(l3a, (2, 2),ignore_border=False) 
    l3 = T.flatten(l3b, outdim=2) 
    l3 = dropout(l3, p_drop_conv) 

    # Fully connected Layer 
    l4 = rectify(T.dot(l3, w4)) 
    l4 = dropout(l4, p_drop_hidden) 

    # Classify the Output 
    pyx = softmax(T.dot(l4, w_o)) 
    return l1, l2, l3, l4, pyx 


# Load the data (tr = training, te = test) 
trX, teX, trY, teY = load.mnist(ntrain=trainSize, ntest=testSize, onehot=True) 


# Reshape training set to be 4-dimensional 
# negative value is to get ordering right (rather than mirror image) 
# Second parameter is color channels 
trX = trX.reshape(-1, 1, 28, 28) 
teX = teX.reshape(-1, 1, 28, 28) 

# Input variables 
X = T.dtensor4() 
Y = T.fmatrix() 


# WEIGHTS 
if os.path.isfile(weightsFile): 
    # Go get saved weights from file 
    [w1, w2, w3, w4, w_o] = pickle.load(open(weightsFile,'rb')) 
else: 
    # Initialize all layer weights 
    # (no. Inputs, no. Outputs, filter height, filter width) 
    # ver isto outra vez, minuto 48 
    w1 = init_weights((32, 1, 3, 3)) # 1 = num canais de cada imagem (cor) 
    w2 = init_weights((64, 32, 3, 3)) 
    w3 = init_weights((128, 64, 3, 3)) 
    w4 = init_weights((128 * 3 * 3, 625)) 
    w_o = init_weights((625, 10)) # from fully connected layer to classifier 


# This sets up the model graph and some vars for noise, which are the internal neurons 
noise_l1, noise_l2, noise_l3, noise_l4, noise_py_x = model(X, w1, w2, w3, w4, 0.2, 0.5) 

# No dropping neurons...so this will be used for prediction 
l1, l2, l3, l4, py_x = model(X, w1, w2, w3, w4, 0., 0.) 

# This makes predictions 
y_x = T.argmax(py_x, axis=1) 

# Compile prediction function - here named complexFunction 
complexFunction = theano.function(inputs=[X], outputs=y_x, allow_input_downcast=True) 

가 자세한 오류 메시지입니다 : 파일 theanoCode.py의 코드 (그것은 길쌈 신경망 분류는로드 모듈 파일에서 mnist 데이터 세트를 읽는 데 사용된다)

그리고 여기에 이벤트 로그입니다 :

</Data></EventData></Event><Event><System><Provider Name="ASP.NET 4.0.30319.0"/><EventID>1325</EventID><Level>3</Level><Task>0</Task><Keywords>Keywords</Keywords><TimeCreated SystemTime="2016-06-05T19:34:20Z"/><EventRecordID>1604538437</EventRecordID><Channel>Application</Channel><Computer>RD000D3A218E0C</Computer><Security/></System><EventData><Data>An unhandled exception occurred and the process was terminated. 

Application ID: /LM/W3SVC/1568611192/ROOT 

Process ID: 647864 

Exception: System.Configuration.ConfigurationErrorsException 

Message: Couldn't find type for class Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35. 

StackTrace: at System.Diagnostics.TraceUtils.GetRuntimeObject(String className, Type baseType, String initializeData) 
    at System.Diagnostics.TypedElement.BaseGetRuntimeObject() 
    at System.Diagnostics.ListenerElement.GetRuntimeObject() 
    at System.Diagnostics.ListenerElementsCollection.GetRuntimeObject() 
    at System.Diagnostics.TraceInternal.get_Listeners() 
    at System.Diagnostics.TraceInternal.WriteLine(String message) 
    at System.Diagnostics.Debug.WriteLine(String message) 
    at Microsoft.Web.Compilation.Snapshots.SnapshotHelper.TakeSnapshotTimerCallback(Object stateInfo) 
    at System.Threading.TimerQueueTimer.CallCallbackInContext(Object state) 
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
    at System.Threading.TimerQueueTimer.CallCallback() 
    at System.Threading.TimerQueueTimer.Fire() 
    at System.Threading.TimerQueue.FireNextTimers() 
    at System.Threading.TimerQueue.AppDomainTimerCallback()</Data></EventData></Event><Event><System><Provider Name=".NET Runtime"/><EventID>1026</EventID><Level>0</Level><Task>0</Task><Keywords>Keywords</Keywords><TimeCreated SystemTime="2016-06-05T19:34:20Z"/><EventRecordID>1604538453</EventRecordID><Channel>Application</Channel><Computer>RD000D3A218E0C</Computer><Security/></System><EventData><Data>Application: w3wp.exe 
Framework Version: v4.0.30319 
Description: The process was terminated due to an unhandled exception. 
Exception Info: System.Configuration.ConfigurationErrorsException 
    at System.Diagnostics.TraceUtils.GetRuntimeObject(System.String, System.Type, System.String) 
    at System.Diagnostics.TypedElement.BaseGetRuntimeObject() 
    at System.Diagnostics.ListenerElement.GetRuntimeObject() 
    at System.Diagnostics.ListenerElementsCollection.GetRuntimeObject() 
    at System.Diagnostics.TraceInternal.get_Listeners() 
    at System.Diagnostics.TraceInternal.WriteLine(System.String) 
    at System.Diagnostics.Debug.WriteLine(System.String) 
    at Microsoft.Web.Compilation.Snapshots.SnapshotHelper.TakeSnapshotTimerCallback(System.Object) 
    at System.Threading.TimerQueueTimer.CallCallbackInContext(System.Object) 
    at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 
    at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 
    at System.Threading.TimerQueueTimer.CallCallback() 
    at System.Threading.TimerQueueTimer.Fire() 
    at System.Threading.TimerQueue.FireNextTimers() 
    at System.Threading.TimerQueue.AppDomainTimerCallback() 

</Data></EventData></Event></Events> 
+0

* 코드는 어디에 있습니까? * [mcve]를 포함하십시오. – jonrsharpe

+0

로깅을 활성화하고 실제 오류 게시 : http://stackoverflow.com/questions/32722143/flask-application-traceback-doesnt-show-up-in-server-log. – davidism

답변

0

등 그러나 코드 및 오류 정보에 따라 GPU를 사용한 멀티 스레드, 메모리 제한 같은 theano으로 문제의 원인에 대한 많은 이유가 있습니다, 이유가 무엇인지 나는 확신 할 수 없다.

나는 실제 문제를 알아 내기 위해 theano 문서 "Debugging Theano: FAQ and Troubleshooting"과 "Azure Web App sandbox"을 참조하려고합니다.

complexFunction 코드를 공유 할 수 있습니까? 나는이 문제를 분석하는데 도움이된다고 생각하며 해결책을 찾기 위해 그것을 재현하려고 노력한다.


업데이트 :

코드 & 이벤트 로그에 따르면, 나는이 문제의 원인 두 가지 이유가 있다고 생각합니다.

  1. 일부 코드 논리 오류로 인해 내부 서버 오류가 발생했지만 코드가 로컬에서 잘 작동하는 경우이 가능성을 무시하십시오.

  2. 과 같은 webapp 구성이 잘못되었으므로 올바르게 구성되었는지 확인하려면 web.config 섹션을 참조하십시오.

+0

Dreamspark 서브 스크립 션을 사용하고 있기 때문에 1GB RAM 및 1GB 스토리지가있는 32 비트 웹 응용 프로그램에만 액세스 할 수 있으므로 메모리 제한이 주요 관심사입니다. 그러나 메모리 사용량을 모니터링 할 때 주어진 시간에 500MB의 작업 메모리에 도달하지 않습니다. Btw, complexFunction 코드가 질문에 포함되었습니다. – Crowing

+0

@Crowing 유용한 정보가 포함 된 게시물을 업데이트했습니다. 희망이 도움이됩니다. –