google-api-dotnet-client: Trainning result in Error message - No model found. Model must first be trained. [404]
What steps will reproduce the problem?
After authentication when I am trying to access the Training status, I am
getting the following exception.
Google.Apis.Requests.RequestError
No model found. Model must first be trained. [404]
Errors [
Message[No model found. Model must first be trained.] Location[ - ] Reason[notFound] Domain[global]
Here is the Code I am using at my end.
public partial class _Default : System.Web.UI.Page
{
private static PredictionService _service; // We don't need individual service instances for each client.
private IAuthorizationState _state;
private OAuth2Authenticator<WebServerClient> _authenticator;
private IAuthorizationState AuthState
{
get
{
return _state ?? HttpContext.Current.Session["AUTH_STATE"] as IAuthorizationState;
}
}
private OAuth2Authenticator<WebServerClient> CreateAuthenticator()
{
// Register the authenticator.
var provider = new WebServerClient(GoogleAuthenticationServer.Description);
provider.ClientIdentifier = ClientCredentials.ClientID;
provider.ClientSecret = ClientCredentials.ClientSecret;
var authenticator = new OAuth2Authenticator<WebServerClient>(provider, GetAuthentication);
//{ NoCaching = true }; // TODO(mlinder): Uncomment when CL is merged.
return authenticator;
}
protected void Page_Load(object sender, EventArgs e)
{
CommandLine.EnableExceptionHandling();
CommandLine.DisplayGoogleSampleHeader("Prediction API");
_authenticator = CreateAuthenticator();
CommandLine.WriteLine();
if (_service == null)
{
_service = new PredictionService(_authenticator);
}
// Check if we received OAuth2 credentials with this request; if yes: parse it.
if (HttpContext.Current.Request["code"] != null)
{
_authenticator.LoadAccessToken();
}
RunPrediction(_service);
CommandLine.PressAnyKeyToExit();
}
private IAuthorizationState GetAuthentication(WebServerClient client)
{
// If this user is already authenticated, then just return the auth state.
IAuthorizationState state = AuthState;
if (state != null)
{
return state;
}
// Check if an authorization request already is in progress.
state = client.ProcessUserAuthorization(new HttpRequestInfo(HttpContext.Current.Request));
if (state != null && (!string.IsNullOrEmpty(state.AccessToken) || !string.IsNullOrEmpty(state.RefreshToken)))
{
// Store and return the credentials.
HttpContext.Current.Session["AUTH_STATE"] = _state = state;
return state;
}
string scope = PredictionService.Scopes.Prediction.GetStringValue();
OutgoingWebResponse response = client.PrepareRequestUserAuthorization(new[] { scope });
response.Send(); // Will throw a ThreadAbortException to prevent sending another response.
return null;
}
private static IAuthorizationState GetAuthentication(NativeApplicationClient client)
{
// You should use a more secure way of storing the key here as
// .NET applications can be disassembled using a reflection tool.
const string STORAGE = "google.samples.dotnet.prediction";
const string KEY = "AF41sdBra7ufra)VD:@#A#a++=3e";
string scope = PredictionService.Scopes.Prediction.GetStringValue();
// Check if there is a cached refresh token available.
IAuthorizationState state = AuthorizationMgr.GetCachedRefreshToken(STORAGE, KEY);
if (state != null)
{
try
{
client.RefreshToken(state);
return state; // Yes - we are done.
}
catch (DotNetOpenAuth.Messaging.ProtocolException ex)
{
CommandLine.WriteError("Using existing refresh token failed: " + ex.Message);
}
}
// Retrieve the authorization from the user.
state = AuthorizationMgr.RequestNativeAuthorization(client, scope);
AuthorizationMgr.SetCachedRefreshToken(STORAGE, KEY, state);
return state;
}
private static void RunPrediction(PredictionService service)
{
// Train the service with the existing bucket data.
CommandLine.WriteAction("Performing training of the service ...");
CommandLine.WriteResult("Bucket", ClientCredentials.BucketPath);
Training training = new Training() { Id = ClientCredentials.BucketPath };
training = service.Training.Insert(training).Fetch();
Thread.Sleep(2000);
// Wait until the training is complete.
while ((training= service.Training.Get(training.Id).Fetch()).TrainingStatus == "RUNNING")
{
CommandLine.Write("..");
Thread.Sleep(1000);
}
CommandLine.WriteLine();
CommandLine.WriteAction("Training complete!");
CommandLine.WriteLine();
// Make a prediction.
CommandLine.WriteAction("Performing a prediction...");
string text = "mucho bueno";
CommandLine.RequestUserInput("Text to analyze", ref text);
var input = new Input { InputValue = new Input.InputData { CsvInstance = new List<string> { text } } };
Output result = service.Training.Predict(input, training.Id).Fetch();
CommandLine.WriteResult("Language", result.OutputLabel);
}
}
Exception is thrown on the following line
training= service.Training.Get(training.Id).Fetch()
What version of the product are you using? On what operating system?
I am testing on Vista and I am using the Prediction API version 3
Attached is my bucket file that I using to trained my Model
Original issue reported on code.google.com by neeraj....@gmail.com on 28 Aug 2011 at 3:49
Attachments:
About this issue
- Original URL
- State: closed
- Created 12 years ago
- Comments: 17